Reputation: 1386
I have built an ARIMA(9,0,2) model with nonzero mean. I would like to use this model to create counter-factual forecasts. That is, conditional on only having the first nine observations, I'm looking for an R function that can produce a forecast for the tenth, eleventh, and so on observations using the ARIMA(9,0,2) model that I estimated by using all of the data.
R functions forecast
and predict
do not, to my knowledge, accomplish the counterfactual portion of this. Function forecast
picks up where your time series ends and makes predictions using the fitted model, but I have not found a way to trick it into giving me forecasts using observations 1-9 to predict observation 10 onward, or using observations 2-10 for predicting observation 11 on onward. Likewise, predict
creates the next several observations picking up where the data stops. I haven't found a workaround for either of these functions.
R function fitted
just creates a 1-step forecast, not a long-run forecast for each time point in the available data.
I've pasted code for creating some fake time-series data, an Arima object and a demonstration of how forecast
does not provide a helpful output for my question.
setseed(2314)
fake.data <- rnorm(10,sd=5)
for(i in 1:200){
model.length <- 9
lower <- length(fake.data)-9+1
upper <- length(fake.data)
new.obs <- rnorm(1,mean=0,sd=0.25)+fake.data[lower:upper]%*%c( -0.1, 0.1, -0.15,0.15,-0.2,0.2,-0.5,0.3,0.9)
fake.data <- c(fake.data, new.obs)
}
plot(fake.data)
fitted.arima <- auto.arima(fake.data, ic="bic")
plot(forecast(fitted.arima))
Clearly the output of forecast
is not a prediction at points in time which were observed.
Upvotes: 2
Views: 534
Reputation: 3329
The forecast
package by Hyndman et. al. has a nice wrapper around ARIMA that allows you to do the previous work with the same result, but a slightly friendlier API (imho).
library(forecast)
m <- Arima(LakeHuron, order=c(9,0,2))
mn <- Arima(LakeHuron, model=m)
predict(mn, n.ahead=10)
Supplying the model=
argument with an argument of a previously generated model does the work of the above.
Upvotes: 1
Reputation: 9618
You can fix the parameters using the fixed
argument. Below an example:
m<-arima(LakeHuron,order=c(9,0,2))
coe<-m$coef
mn<-arima(LakeHuron[1:9],order=c(9,0,2),fixed=coe)
sum(coe==mn$coef)
12 # all coefficients are equal
predict(mn,n.ahead =10)
Upvotes: 2