[R] [FORGED] Forecast and xreg
Rolf Turner
r.turner at auckland.ac.nz
Thu Jan 14 02:53:02 CET 2016
I know from nothing about arimax or the forecast package, but it sounds
to me like you are expecting magic. An analogy:
Suppose you are doing a simple linear regression of y on x1 and x2 with
y and x1 having 49 entries each, but with x2 having only 40. Assume
that y, x1 and x2 are properly aligned but there are no x2 data for the
last 9 entries of x2. Would you really expect to be able to make use of
the last 9 entries of y and x1 in fitting your model?
I could be wrong (I was once; back in 1968 --- I thought I'd made a
mistake and I hadn't; :-) ) but I don't think there is any scope for
applying an EM algorithm, since x2 is not a random variable so taking
expectations of the likelihood w.r.t. the missing data makes no sense.
I guess if you assumed (e.g.) a joint Gaussian distribution for
(y,x1,x2) then you could "do EM". But that would not be a realistic
assumption in most instances.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
On 14/01/16 10:12, Lorenzo Isella wrote:
> Dear All,
> Please consider the small self-contained code at the end of the email.
> It is an artificial arimax model with a matrix of regressors xreg.
> In the script, xreg has as many rows as the number of data points in
> the time series "visits" I want to model.
> Now, my problem is the following: I am in a similar situation, as in
> the example, but my matrix of auxiliary regressors is "shorter" than
> the time series, e.g. I am trying to do something like (see the last
> line of my script)
>
> modArima <- auto.arima(visits, xreg=xreg[1:40, ])
>
> Which is simply not allowed by the forecast package.
> Is there any workaround?
> I do not want to throw away the information, so I would prefer *not*
> to disregard the predictors just because they are not synchronized to
> the time series, nor shorten artificially the time series because it
> is longer than my predictor matrix.
> Any suggestion is appreciated.
> Regards
>
> Lorenzo
>
>
> ########################################################################
> library(forecast)
> # create some artifical data
> modelfitsample <-
> data.frame(Customer_Visit=rpois(49,3000),Weekday=rep(1:7,7),
> Christmas=c(rep(0,40),1,rep(0,8)),Day=1:49)
>
> # Create matrix of numeric predictors
> xreg <-
> cbind(Weekday=model.matrix(~as.factor(modelfitsample$Weekday)),
> Day=modelfitsample$Day,
> Christmas=modelfitsample$Christmas)
>
> # Remove intercept
> xreg <- xreg[,-1]
>
> # Rename columns
> colnames(xreg) <-
> c("Mon","Tue","Wed","Thu","Fri","Sat","Day","Christmas")
>
> # Variable to be modelled
> visits <- ts(modelfitsample$Customer_Visit, frequency=7)
>
> # Find ARIMAX model
> modArima <- auto.arima(visits, xreg=xreg)
More information about the R-help
mailing list