R语言时间序列作业

上传人:ail****e2 文档编号:55763796 上传时间:2022-02-18 格式:DOCX 页数:17 大小:284.11KB
返回 下载 相关 举报
R语言时间序列作业_第1页
第1页 / 共17页
R语言时间序列作业_第2页
第2页 / 共17页
R语言时间序列作业_第3页
第3页 / 共17页
点击查看更多>>
资源描述
2016年第二学期时间序列分析及应用R语言课后作业第三章趋势3.4(a) data(hours);plot(hours,ylab=Monthly Hours,type=o)画出时间序列图19831984198519861987Time(b) data(hours);plot(hours,ylab=Monthly Hours,type=l)19831984198519861987Timetype=o表示每个数据点都叠加在曲线上;type=b表示在曲线上叠加数据点,但是该数据点附近是断开的;type=T 表示只显示各数据点之间的连接线段;type=p,只想显示数据点。points(y=hours,x=time(hours),pch=as.vector(season(hours)98D -A9898TimJM mjfD q JsruoH VHVnoMD- . N sr?fn jmma3.10(a) data(hours);hours.lm=lm(hourstime(hours)+I(time(hours)A2);summary(hours.lm)用最小二乘法拟合二次趋势,结果显示如下:Call:lm(formula = hours time(hours) + I(time(hours)A2)Residuals:Min 1Q Median 3Q Max -1.00603 -0.25431 -0.022670.22884 0.98358Coefficients: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+024.431 4.31e-05 *I(time(hours)A2) -1.299e-012.933e-02 -4.428 4.35e-05 *Signif. codes: 0 * 0.001* 0.01* 0.05 .0.11Residual standard error: 0.423 on 57 degrees of freedomMultiple R-squared: 0.5921, Adjusted R-squared: 0.5778F-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)标准残差的时间序列,应用月度绘图标志。(为了更容易识别季节性) 带季节性图标的的残差-时间图opa urtrseR deN_0adn?s19831984198519861987as.vector(time(hours)2 1 0 1-2(c) runs(rstudent(hours.lm)对标准差进行游程检验$pvalue1 0.00012$observed.runs1 16$expected.runs1 30.96667$n11 31$n21 29$k1 0结果解释:P值为0.00012,表明非随机性是合理的。(d) acf(rstudent(hours.lm)标准残差的样本自相关函数季节均值模型残差的样本自相关系数Series rstudent(hours.lm)4 -402020FC 00(e) qqnorm(rstudent(hours.lm);qqline(rstudent(hours.lm)(QQ 图)Normal Q-Q PlotTheoretical Quantiles正态性可以通过正态得分或者分位数-分位数(QQ)图来检验。此处的直线型图形支持了该模型中随机项是正态分布的假设。hist(rstudent(hours.lm),xlab=Standardized Residuals)标准残差的直方图(季节均值模型的标准残差直方图)Histogram of rstudent(hours.lm)Standardized Residualsshapiro.test(rstudent(hours.lm)正态性检验(Shapiro-Wilk检验)本质是:计算残差与相应的正态分位数之间的相关系数。相关性越小,就越有理由否定正态性。Shapiro-Wilk normality testdata: rstudent(hours.lm)W = 0.99385, p-value = 0.9909根据上面的检验结果,我们不能拒绝模型的随机项是正态分布的假设。第四章平稳时间序列模型14.4-1一吐12一7第五章非平稳时间序列模型5.1(a) ARMA (2,1)p=2,q=1,参数值 e 和 0()1=1()2=-0.2501=0.1(b) IMA(2,0)p=2,d=1,q=0,参数值。和 0(c) ARMA(2,2) p=2,q=2,参数值。和 0()1=0.5()2=-0.5 0 1=0.5 data(google) plot(google)收益率数据的时间序列图MU300iTHMM acf(google)5Bile% gpugle pacf(google)gnglle_uwm?根据ACF和PACF可以得知,无自相关。(b)计算google日收益率均值。 t.test(google,alternative = greater) One Sample t-test data: googlet = 2.5689, df = 520, p-value = 0.00524alternative hypothesis: true mean is greater than 095 percent confidence interval: 0.000962967Infsample estimates: mean of x0.002685589x的均值为0.002685589 ,备择假设为:均值异于0,根据P值显示,0.00524接受备择假设。 (c)McLeod-Li 检3佥 ARCH效应。 win.graph(width = 4.875,height = 3,pointsize = 8) McLeod.Li.test(y=google)根据图显示,所有滞后值在5%的水平上均显著。说明数据具有ARCH特征。(d)识别GARCH莫型,估计识别的模型并对拟合的模型进行模型诊断检验。 eacf(googleA2)取值平方的样本 EACFAR/MA0 1 2 3 4 5 6 7 8 9 10 11 12 130 x x o o o o o o o x o o o x1 x o o o o o o o o x o o o x2 x o o o o o o o o x o o o x3 x x x oo oo oo x ooox4 x x x oo oo oo o oooo5 x x x oo oo oo o oooo6 x x x xo oo oo o oooo7 o x x oo xo oo o oooo eacf(abs(google)绝对值的样本 EACFAR/MA0 1 2 3 4 5 6 7 8 9 10 11 12 130 x x x o o o x o o x o o x x1 x o o o o o o o o o o o o x2 x x o o o o o o o o o o o x3 x x x o o o o o o o o o o x4 x o x o o o o o o o o o o o5 x o x o x o o o o o o o o o6 o x x x x x o o o o o o o o7 x o x x x o x o o o o o o o根据上图,得知设定GARCH(1,1)模型。Google日收益率的平方值相应的样本EACF也得知模型 GARCH(1,1)符合。检验模型: m1=garch(x=google,order = c(1,1) summary(m1)Call:garch(x = google, order = c(1, 1)Model:GARCH(1,1)Residuals:Min 1Q Median 3Q Max-3.64597 -0.46486 0.08232 0.65379 5.73937Coefficient(s):Estimate Std. Error t value Pr(|t|)a0 5.058e-05 1.232e-05 4.106 4.03e-05 *a1 1.264e-01 2.136e-02 5.920 3.21e-09 *b1 7.865e-01 3.578e-02 21.980 2e-16 * Signif. codes: 0 * 0.001* 0.01* 0.05. 0.1 1Diagnostic Tests:Jarque Bera Testdata: ResidualsX-squared = 223.86, df = 2, p-value plot(residuals(m1),type=h,ylab=Standardized Residuals)10020030040 000Time标准残差的QQ正态得分图 win.graph(width = 2.5,height = 2.5,pointsize = 8) qqnorm(residuals(m1);qqline(residuals(m1)Normal Q Q PlotTheoretics QuantBes如果模型识别正确,那么残差应该是近似独立同分布的。从上 qq图中显示并不明确。所以我们 进行广义混合检验。 绘制google日收益率的 GARCH (1, 1)模型的标准残差平方的样本ACFacf(residuals(m12,na.action=na.omit)Series re5iduals(m1)A2从图形中得出总体印象是残差平方序列不相关。进行广义混合检验得到的p值gBox(m1,method=squared)结果显示错误! ! !不清楚为什么! ! !在这里继续使用绝对标准残差重新对模型进行检验。绝对标准残差的样本ACFacf(abs(residuals(m1),na.action=na.omit)Snv I。事 忤i-eIi h 1/gBox(m1,method=absolute)(e)绘制并评论估计的条件方差的时间序列图器吕 dswo5woasooan -。匚三七口3;=_一4,0 一图中显示出来有几个时期的波动率较高。(f)对拟合模型的标准残差绘制QQ图qqnorm(residuals(m1);qqline(residuals(m1)Harm al Q-0 P ilot心残差看起来并不正常。(g)构造 bl 的 95%的置信区间。(0.7865-1.96*0.03578 , 0.7865+1.96*0.03578 ) = (0.7164, 0.8566)
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 演讲稿件


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!