简体   繁体   English

在R中提取反事实ARIMA预测的函数

[英]Function for extracting counter-factual ARIMA forecasts in R

I have built an ARIMA(9,0,2) model with nonzero mean. 我建立了一个非零均值的ARIMA(9,0,2)模型。 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函数,该函数可以生成对第十 ,十一等的预测,依此类推,使用我估计的ARIMA(9,0,2)模型使用所有数据。

R functions forecast and predict do not, to my knowledge, accomplish the counterfactual portion of this. 据我所知,R函数的forecastpredict并不能完成这一反事实部分。 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. 函数forecast从您的时间序列的结尾处提取并使用拟合模型进行预测,但是我还没有找到一种方法来诱使它使用观测值1-9预测未来的观测值10或使用观测值2-10进行预测观察11起。 Likewise, predict creates the next several observations picking up where the data stops. 同样, predict将在数据停止的位置创建接下来的几个观察值。 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. fitted R函数仅会创建1步预测,而不是可用数据中每个时间点的长期预测

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. 我粘贴了用于创建一些伪造的时间序列数据的代码,一个Arima对象,并演示了forecast如何无法为我的问题提供有用的输出。

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. 显然, forecast的输出不是在观察到的时间点的预测。

You can fix the parameters using the fixed argument. 您可以使用fixed参数来fixed参数。 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)

The forecast package by Hyndman et. Hyndman等人的forecast 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). ARIMA有一个很好的包装器,可以使您以相同的结果完成以前的工作,但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. model=参数提供先前生成的模型的参数即可完成上述工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM