R语言时间序列作业

2020-04-14 06:36

2016年第二学期时间序列分析及应用R语言课后作业 第三章 趋势

3.4(a) data(hours);plot(hours,ylab='Monthly Hours',type='o') 画出时间序列图

Monthly Hours39.039.540.040.541.041.5198319841985Time19861987

(b) data(hours);plot(hours,ylab='Monthly Hours',type='l')

Monthly Hours39.039.540.040.541.041.5198319841985Time19861987

type='o' 表示每个数据点都叠加在曲线上;type='b' 表示在曲线上叠加数据点,但是该数据点附近是断开的;type='l' 表示只显示各数据点之间的连接线段;type='p' 只想显示数据点。

points(y=hours,x=time(hours),pch=as.vector(season(hours)))

41.5DDDADNSOSNJMFJMAAOJMMJFAJ41.039.5SNJOFMSNJMJOAAMJJJMAAJJMADFMNJF19841985TimeMonthly Hours39.040.0AOJS40.5198319861987

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))

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 *** 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

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(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))) 标准残差的时间序列,应用月度绘图标志。(为了更容易识别季节性)

带季节性图标的的残差-时间图

D2DSNODAFJMJAMSNJJMMAJAFNSOJMDJMSNMJFAOAStandardized Residuals1JDJA-1MJANM0AOJJMAOJSJ-2FF19831984198519861987as.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))

标准残差的样本自相关函数

季节均值模型残差的样本自相关系数

Series rstudent(hours.lm)ACF-0.4-0.20.00.20.45Lag1015

(e) qqnorm(rstudent(hours.lm));qqline(rstudent(hours.lm)) (QQ图)

Normal Q-Q PlotSample Quantiles-2-1012-2-10Theoretical Quantiles12

正态性可以通过正态得分或者分位数-分位数(QQ)图来检验。此处的直线型图形支持了该模型中随机项是正态分布的假设。

hist(rstudent(hours.lm),xlab='Standardized Residuals') 标准残差的直方图(季节均值模型的标准残差直方图)

Histogram of rstudent(hours.lm)Frequency05101520-3-2-10123Standardized Residuals

shapiro.test(rstudent(hours.lm))

正态性检验(Shapiro-Wilk检验)本质是:计算残差与相应的正态分位数之间的相关系数。相关性越小,就越有理由否定正态性。 Shapiro-Wilk normality test data: rstudent(hours.lm) W = 0.99385, p-value = 0.9909

根据上面的检验结果,我们不能拒绝模型的随机项是正态分布的假设。 第四章 平稳时间序列模型 4.4

1????1-?12-? ?1??2第五章 非平稳时间序列模型

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=2,q=2,参数值φ和θ φ1=0.5 φ2=-0.5 Θ1=0.5 Θ2=-0.25 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') 时间序列图

Winnebago Monthly Sales050010001500196719681969Time197019711972

表明公司的休闲车的销量在逐渐增加。

(b) plot(log(winnebago),type='o',ylab='Log(Monthly Sales)') 取对数之后的时间序列图

Log(Monthly Sales)4.05.06.07.0196719681969Time197019711972

仍然呈现增加的趋势,但是比没有取对数之前增加的缓慢一些。

(c) percentage=na.omit((winnebago-zlag(winnebago))/zlag(winnebago)) 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]) [1] 0.9646886

Percentage Change-0.50.00.51.01.5-0.50.00.51.0Difference of Logs

结果显示: 0.96认为一致。 第六章 模型识别

6.29(a) set.seed(762534);series=arima.sim(n=60,list(ar=0.4,ma=0.6)) phi=0.4;theta=0.6;ACF=ARMAacf(ar=phi,ma=-theta,lag.max=10)

plot(y=ACF[-1],x=1:10,xlab='Lag',ylab='ACF',type='h',ylim=c(-.2,.2));abline(h=0)

ACF-0.2-0.10.00.10.2246Lag810

(b) acf(series)


R语言时间序列作业.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:圆管涵、盖板涵分项工程质量检验评定表

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: