欢迎来到天天文库
浏览记录
ID:61672951
大小:214.15 KB
页数:18页
时间:2021-03-08
《R语言时间序列作业.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、2016年第二学期时间序列分析及应用R语言课后作业第三章趋势3.4(a)data(hours);plot(hours,ylab='MonthlyHours',type='o')画出时间序列图5.140.14s5ru.o04Hylh0tn.o0M45.930.9319831984198519861987Time(b)data(hours);plot(hours,ylab='MonthlyHours',type='l')5.140.14s5ru.o0H4ylh0tn.o0M45.930.9319831984198519861987Timetype='o'表示每个数据点都叠加在曲线上;t
2、ype='b'表示在曲线上叠加数据点,但是该数据点附近是断开的;type='l'表示只显示各数据点之间的连接线段;type='p'只想显示数据点。points(y=hours,x=time(hours),pch=as.vector(season(hours)))5D.D140DDJ.1ANSN4JMMsSNJSOJF5OFMSNJMAOrJMJMu.Oo0AAAAH4MyJJJMFlAJh0tAJn.Jo0M4MA5DF.M93N0J.AO93JSF19831984198519861987Time3.10(a)data(hours);hours.lm=lm(hours~tim
3、e(hours)+I(time(hours)^2));summary(hours.lm)用最小二乘法拟合二次趋势,结果显示如下:Call:lm(formula=hours~time(hours)+I(time(hours)^2))Residuals:Min1QMedian3QMax-1.00603-0.25431-0.022670.228840.98358Coefficients:EstimateStd.ErrortvaluePr(>
4、t
5、)(Intercept)-5.122e+051.155e+05-4.4334.28e-05***time(hours)5.159e+021.164e
6、+024.4314.31e-05***I(time(hours)^2)-1.299e-012.933e-02-4.4284.35e-05***---Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1Residualstandarderror:0.423on57degreesoffreedomMultipleR-squared:0.5921,F-statistic:41.37on2and57DF,AdjustedR-squared:p-value:7.97e-120.5778(b)plot(y=rstudent(hours.lm),x=a
7、s.vector(time(hours)),type='l',ylab='StandardizedResiduals')points(y=rstudent(hours.lm),x=as.vector(time(hours)),pch=as.vector(season(hours)))标准残差的时间序列,应用月度绘图标志。(为了更容易识别季节性)带季节性图标的的残差-时间图D2DSNDODsAJl1aJJFMuJdiMsSNeDAMMRMSNNJFd0JeASJzOiMOAOdNAJMrJaAJMdJAAn1MAaSOJt-JSMFAJJ2-FF19831984198519861987a
8、s.vector(time(hours))(c)runs(rstudent(hours.lm))对标准差进行游程检验$pvalue[1]0.00012$observed.runs[1]16$expected.runs[1]30.96667$n1[1]31$n2[1]29$k[1]0结果解释:P值为0.00012,表明非随机性是合理的。(d)acf(rstudent(hours.lm))标准残差的样本自相关函数季节均值模型残差的样本自相关系数Seriesrstudent(hours.lm)4.02.0FCA0.02.0-4.0-51015Lag(e)qqnorm(rstudent(hou
9、rs.lm));qqline(rstudent(hours.lm))(QQ图)NormalQ-QPlot21selitnauQ0elpmaS1-2--2-1012TheoreticalQuantiles正态性可以通过正态得分或者分位数-分位数(QQ)图来检验。此处的直线型图形支持了该模型中随机项是正态分布的假设。hist(rstudent(hours.lm),xlab='StandardizedResiduals')标准残差的直方图(季节均值模
此文档下载收益归作者所有