R语言季节性arima模型案例附代码数据文档格式.docx
- 文档编号:18890673
- 上传时间:2023-01-02
- 格式:DOCX
- 页数:6
- 大小:52.54KB
R语言季节性arima模型案例附代码数据文档格式.docx
《R语言季节性arima模型案例附代码数据文档格式.docx》由会员分享,可在线阅读,更多相关《R语言季节性arima模型案例附代码数据文档格式.docx(6页珍藏版)》请在冰豆网上搜索。
head(data)
##sales
##1105715
##2120136
##3181669
##4239813
##5159980
##6164760
plot(as.numeric(data[,1]),type="
l"
#分解为趋势和季节成分
#从数据来看,有明显得波动趋势,因此可能存在季节性趋势,需要进行季节性差分。
#计算趋势(使用适当的移动平均线)和季节性成分。
将时间趋势,季节性因素和剩余序列与时间对应,并对您的地块进行评论。
kingstimeseries<
-ts(as.numeric(data[,1]),frequency=12)
kingstimeseries
##JanFebMarAprMayJunJulAugSepOctNovDec
##13819251415242921232833
##2262731373032364134353944
##338404750424351554546544
##448495695253713561216
##510111822172021
kingstimeseriescomponents<
-decompose(kingstimeseries)
kingstimeseriescomponents$seasonal#gettheestimatedvaluesoftheseasonalcomponent
##JanFebMarAprMayJun
##1-1.16493060.60590287.7934028-4.41493065.37673617.1684028
##2-1.16493060.60590287.7934028-4.41493065.37673617.1684028
##3-1.16493060.60590287.7934028-4.41493065.37673617.1684028
##4-1.16493060.60590287.7934028-4.41493065.37673617.1684028
##5-1.16493060.60590287.7934028-4.41493065.37673617.1684028
##JulAugSepOctNovDec
##1-2.17534722.7204861-5.5503472-4.25868061.4913194-7.5920139
##2-2.17534722.7204861-5.5503472-4.25868061.4913194-7.5920139
##3-2.17534722.7204861-5.5503472-4.25868061.4913194-7.5920139
##4-2.17534722.7204861-5.5503472-4.25868061.4913194-7.5920139
##5-2.17534722.7204861
plot(kingstimeseriescomponents)
#从差分图来看,数据有明显得季节趋势,需要进行季节性差分。
#预测销售量,使用这种方法计算预测值,并绘制一个图中观察到的时间序列和预测值。
library(forecast)
mm<
-auto.arima(kingstimeseries)
plot(kingstimeseries)
lines(mm$fitted,col="
red"
#从图中看,拟合程度一般,拟合曲线在实际数据周围。
#绘制观测时间序列和剩余序列的自相关函数。
将它们放在同一页面上(但在两个不同的面板上)。
par(mfrow=c(2,1))
acf(kingstimeseries)
acf(mm$residuals)
#从残差来看,落入置信区间,因此模型拟合良好。
#Thedatafiletsdata.txtcontainstheobserveddataonatimeseries.
#Makeatimeseriesplotthesampleautocorrelationfunctionforthisdata.
#Putthesetwoplotsonthesamepage(butontwopanels).Isthislikelytobeastationaryprocess?
Doesthislooksimilartoawhitenoise?
Explain.
data=read.table("
tsdata.txt"
header=T)
##x
##152.4361
##254.6242
##355.1351
##454.1483
##553.3472
##653.8972
acf(data[,1])
#从图中我们发现数据没有落入置信区间,因此不是平稳数据
#(b)(5points)Makeatimeseriesplotofthedifferencedseriesofthistimeseriesdata.
#Alsoconstructthesampleautocorrelationfunctionofthedifferencedseries.Put
#thesetwoplotsonthesamepage(butontwopanels).Isthedifferencedserieslikely
#tobeastationaryprocess?
plot(diff(as.numeric(data[,1])),type="
acf((diff(as.numeric(data[,1]))))
#从图上我们发现差分后的数据落入置信区间,因此事平稳数据
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 季节性 arima 模型 案例 代码 数据