美国劳工统计局使用ARIMA对全国失业率进行季节性调整,但不针对各个县。我需要帮助强制R中的ARIMA对每个美国县进行季节性调整。
我可以通过使用
auto.arima(mytimeseries)
来获得ARIMA模型,但我无法弄清如何减去季节性成分(就像使用(decompose(mytimeseries))$seasonal
那样容易)。该网站https://onlinecourses.science.psu.edu/stat510/?q=book/export/html/51暗示我应该能够仅减去ARIMA残差:
predicteds = oilindex - expsmoothfit$residuals
但是当我尝试时,它看起来一点也不正确(肉眼观察)--它似乎根本没有识别出季节性变化的大部分。
我想也许auto.arima()
选择的模型很差,但当我将该模型与原始数据绘制在同一图上时,它看起来非常好。
这个网站http://www.statoek.wiso.uni-goettingen.de/mitarbeiter/ogi/pub/r_workshop.pdf讲解了如何使用带有序列的predict()进行平滑处理,但我无法使其工作:我无法确定我的data.frame(mytimeseries[date=seq])
行是否有误或者arima对象是否具有与gam
对象相同的方法,因此预测无法工作。
所以:我如何使用ARIMA从数据中去除季节性?任何帮助都将不胜感激!
以下是我目前的一个示例。(我是R新手,所以无疑,这段代码是次优的。)
# I put unadjusted values for one county at
# http://tmp.webfoot.com/tmp/tmp/unemployment17019.csv
a = read.table("/tmp/unemployment17019.csv", header=FALSE)
# there is probably a simple seven-character way of doing the next line...
all = c(a[1,], a[2,], a[3,], a[4,], a[5,], a[6,], a[7,], a[8,], a[9,], a[10,], a[11,], a[12,], a[13,], a[14,], a[15,], a[16,], a[17,], a[18,], a[19,], a[20,], a[21,], a[22,])
timeseries=ts(as.numeric(all), frequency=12, start=1990)
arimabestfit = forecast::auto.arima(timeseries)
title("Iroquois County", xlab="Date", ylab="Unemployment Rate")
legend(1991,12,c("unadjusted", "adjusted"), col=c("grey", "red"), cex=0.8, lty=1)
plot((timeseries - arimabestfit$residuals), col="red", ylim=c(0,12))
lines(timeseries, col="grey")
all <- c(t(as.matrix(a)))
这行代码可以压缩成一行(未经测试),很抱歉无法帮助您解决主要问题。 - tim riffe