简体   繁体   English

使用R更新ARIMA预测

[英]Updating ARIMA Forecasts with R

I would like to know how can I do a Updating ARIMA forecast on R. I want to forecast a monthly time series with a lead time equal to 1 month. 我想知道如何在R上进行更新ARIMA预测。我想预测提前期等于1个月的每月时间序列。 for example, if my last observation is for february and I want forecast for March, April and May. 例如,如果我的上次观察是2月,而我想预测3月,4月和5月。 after a first step, the value for March becomes available and I would like to use this new data with previous input data to forecast April and May. 第一步之后,三月份的值可用,我想将此新数据与以前的输入数据一起使用来预测四月和五月。 at the second step, I want to use my original input data and the estimated value of March and April to forecast May. 在第二步中,我想使用原始输入数据以及3月和4月的估计值来预测5月。 etc. but my original input data is equal to 600 month and I want to forecast 300 months. 等等,但我的原始输入数据等于600个月,我想预测300个月。 Please, Could you help me? 拜托,你能帮我吗?

ts.month <- ts(month, start=c(1970,10), frequency=12)
tsf.month <- diff(ts.month)
tss.month <- diff(tsf.month)


T <- length (tss.month)     # observed data from 1970 to 2000
index <- 1:(T-1)
res <- forecast(arima(tss.month[index], c(12, 0, 1)), h=1,
                level=c(80,95), fan=FALSE, xreg=NULL,  
                bootstrap=FALSE, npaths=5000)
ts.res <- ts(res$mean, start=c(1991,10), frequency=12)

I tried this following method for the first and second month, but of course I can't use it for 300 months, and the result is wrong maybe cause of the cbind. 我在第一个月和第二个月尝试了以下方法,但是我当然不能在300个月内使用它,结果可能是错误的,可能是结扎的原因。

T <- length (tss.month)
index <- 1:(T-1)
res1 <- forecast(arima(tss.month[index], c(12, 0, 1)), h=1,
            level=c(80,95), fan=FALSE, xreg=NULL,  
            bootstrap=FALSE, npaths=5000)

ts.res <- ts(res1$mean, start=c(1991,10), frequency=12)
ttt <- ts.intersect(tss.month, ts.res)
ts.tt <- ts(ttt, start=c(1960,12), frequency=12)


T <- length (ts.tt)
index <- 1:(T-1)
res2 <- forecast(arima(ts.tt [index], c(12, 0, 1)), h=1,
             level=c(80,95), fan=FALSE, xreg=NULL,  
             bootstrap=FALSE, npaths=5000)
ts.res2 <- ts(res2$mean, start=c(1991,11), frequency=12)
ttt2 <- rbind(tss.month, ts.res2)
ts.tt2 <- ts(ttt2, start=c(1960,12), frequency=12)

You can append the value through rbind and re-run the ARIMA and forecast. 您可以通过rbind附加值,然后重新运行ARIMA和预测。 My example: 我的例子:

tail(data)
             total      dates
2015-06-02 37071.08 2015-06-02
2015-06-03 36722.21 2015-06-03
2015-06-04 28785.25 2015-06-04
2015-06-05 24800.79 2015-06-05
2015-06-06 13361.47 2015-06-06
2015-06-07 14050.93 2015-06-07
fit<-auto.arima(data$total,ic=c("aicc","aic", "bic"),allowdrift=TRUE)
forecast(fit,h=1)
Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
1883 28960.05 25876.42 32043.69 24244.04 33676.07

To add the new ACTUAL data point when you receive it you could: 要在收到新的ACTUAL数据点时添加它,您可以:

toAdd<-data.frame(total=34455.21,dates="")
new.data<-rbind(data,toAdd)

This data set had strong seasonality (ARIMA(3,1,3). 该数据集具有很强的季节性(ARIMA(3,1,3)。

fit<-auto.arima(new.data$total,ic=c("aicc","aic", "bic"),allowdrift=TRUE)
forecast(fit,h=1)
Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
1884       28684.03 25597.14 31770.92 23963.04 33405.02

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

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