Imputing missing values using ARIMA model

余生颓废 提交于 2019-12-03 21:20:52

fitted gives in-sample one-step forecasts. The "right" way to do what you want is via a Kalman smoother. A rough approximation good enough for most purposes is obtained using the average of the forward and backward forecasts for the missing section. Like this:

x <- AirPassengers
x[90:100] <- NA
fit <- auto.arima(x)
fit1 <- forecast(Arima(AirPassengers[1:89],model=fit),h=10)
fit2 <- forecast(Arima(rev(AirPassengers[101:144]), model=fit), h=10)

plot(x)
lines(ts(0.5*c(fit1$mean+rev(fit2$mean)), 
  start=time(AirPassengers)[90],freq=12), col="red")

stats0007

As said by Rob, using a Kalman Smoother is usually the "better" solution.

This can for example be done via the imputeTS package (disclaimer: I maintain the package). (https://cran.r-project.org/web/packages/imputeTS/index.html)

library("imputeTS")
x <- AirPassengers
x[90:100] <- NA
x <- na.kalman(x, model = "auto.arima")

Internally the imputeTS package performs KalmanSmoothing on the State Space Representation of the ARIMA model obtained by auto.arima.

Even if the theoretical background is not easy to understand, it usually gives very good results :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!