R语言时间序列作业

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Residuals:
Min 1Q Median 3Q Max
-1.00603 -0.25431 -0.02267 0.22884 0.98358
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.122e+05 1.155e+05 -4.433 4.28e-05 ***
正态性检验(Shapiro-Wilk检验)本质是:计算残差与相应的正态分位数之间的相关系数。相关性越小,就越有理由否定正态性。
Shapiro-Wilk normality test
data: rstudent(hours.lm)
W = 0.99385, p-value = 0.9909
根据上面的检验结果,我们不能拒绝模型的随机项是正态分布的假设。
time(hours) 5.159e+02 1.164e+02 4.431 4.31e-05 ***
I(time(hours)^2) -1.299e-01 2.933e-02 -4.428 4.35e-05 ***
---
Signif. codes: 0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1
[1] 0.9646886
Residual standard error: 0.423 on 57 degrees of freedom
Multiple R-squared: 0.5921, Adjusted R-squared: 0.5778
F-statistic: 41.37 on 2 and 57 DF, p-value: 7.97e-12
时间序列图
表明公司的休闲车的销量在逐渐增加。
(b)plot(log(winnebago),type='o',ylab='Log(Monthly Sales)')
取对数之后的时间序列图
仍然呈现增加的趋势,但是比没有取对数之前增加的缓慢一些。
(c)percentage=na.omit((winnebago-zlag(winnebago))/zlag(winnebago))
标准残差的时间序列,应用月度绘图标志。(为了更容易识别季节性)
带季节性图标的的残差-时间图
(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))
标准残差的样本自相关函数
季节均值模型残差的样本自相关系数
(e)qqnorm(rstudent(hours.lm));qqline(rstudent(hours.lm))
2016年第二学期时间序列分析及应用R语言课后作业
第三章趋势
3.4(a)data(hours);plot(hours,ylab='Monthly Hours',type='o')
画出时间序列图
(b)data(hours);plot(hours,ylab='Monthly Hours',type='l')
第四章平稳时间序列模型
4.4
第五章非平稳时间序列模型
5.1(a) ARMA (2,1) p=2,q=1,参数值φ和θ
φ1=1φ2=-0.25Θ1=0.1
(b) IMA(2,0) p=2,d=1,q=0,参数值φ和θ
(c) ARMA(2,2) p=Байду номын сангаас,q=2,参数值φ和θ
φ1=0.5φ2=-0.5Θ1=0.5Θ2=-0.25
3.10(a)data(hours);hours.lm=lm(hours~time(hours)+I(time(hours)^2));summary(hours.lm)
用最小二乘法拟合二次趋势,结果显示如下:
Call:
lm(formula = hours ~ time(hours) + I(time(hours)^2))
(QQ图)
正态性可以通过正态得分或者分位数-分位数(QQ)图来检验。此处的直线型图形支持了该模型中随机项是正态分布的假设。
hist(rstudent(hours.lm),xlab='Standardized Residuals')
标准残差的直方图(季节均值模型的标准残差直方图)
shapiro.test(rstudent(hours.lm))
type='o'表示每个数据点都叠加在曲线上;type='b'表示在曲线上叠加数据点,但是该数据点附近是断开的;type='l'表示只显示各数据点之间的连接线段;type='p'只想显示数据点。
points(y=hours,x=time(hours),pch=as.vector(season(hours)))
win.graph(width=3,height=3,pointsize=8)
plot(x=diff(log(winnebago))[-1],y=percentage[-1],ylab='Percentage Change',xlab='Difference of Logs')
cor(diff(log(winnebago))[-1],percentage[-1])
(b)plot(y=rstudent(hours.lm),x=as.vector(time(hours)),type='l',ylab='Standardized Residuals')
points(y=rstudent(hours.lm),x=as.vector(time(hours)),pch=as.vector(season(hours)))
5.7(a) A:AR(2)φ1=0.9φ2=0.09
B:IMA(1,1)Θ1=0.1
(b)一个是固定的一个是不固定的。
5.11(a)data(winnebago);win.graph(width=6.5,height=3,pointsize=8)
plot(winnebago,type='o',ylab='Winnebago Monthly Sales')
相关文档
最新文档