


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、2016 年第二學期時間序列分析及應用 R 語言課后作業(yè) 第三章 趨勢3.4(a) data(hours);plot(hours,ylab='Monthly Hours',type='o')畫出時間序列圖(b) data(hours);plot(hours,ylab='Monthly Hours',type='l')type='o' 表示每個數(shù)據(jù)點都疊加在曲線上; type='b' 表示在曲線上疊加數(shù)據(jù)點,但是該數(shù) 據(jù)點附近是斷開的; type='l' 表示只顯示各數(shù)據(jù)點之間的連接線
2、段; type='p' 只想顯示數(shù)據(jù) 點。points(y=hours,x=time(hours),pch=as.vector(season(hours).5.0M.5.04.0.004.5.0MJD1983 1984 198519861987Time3.10(a) data(hours);hours.lm=lm(hourstime(hours)+I(time(hours)2);summary(hours.lm)用最小二乘法擬合二次趨勢,結(jié)果顯示如下:Call: lm(formula = hours time(hours) + I(time(hours)2)Residuals:
3、Min 1Q Median 3Q Max-1.00603 -0.25431 -0.02267 0.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+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 *
4、39; 0.01 * ' 0.05 .' 0.1 ' 1Residual 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 Res
5、iduals') points(y=rstudent(hours.lm),x=as.vector(time(hours),pch=as.vector(season(hours)標準殘差的時間序列,應用月度繪圖標志。(為了更容易識別季節(jié)性)帶季節(jié)性圖標的的殘差 -時間圖slaudiseRdezidradnatS19831984 1985 19861987as.vector(time(hours)(c) runs(rstudent(hours.lm) 對標準差進行游程檢驗 $pvalue1 0.00012$observed.runs1 16$expected.runs1 30.96667
6、$n11 31 $n21 29$k1 0結(jié)果解釋: P 值為 0.00012,表明非隨機性是合理的。(d) acf(rstudent(hours.lm)標準殘差的樣本自相關(guān)函數(shù)季節(jié)均值模型殘差的樣本自相關(guān)系數(shù)Series rstudent(hours.lm)FCA10ga(e) qqnorm(rstudent(hours.lm);qqline(rstudent(hours.lm)(QQ 圖)Normal Q-Q Plot-2 -1 0 1 2Theoretical Quantiles正態(tài)性可以通過正態(tài)得分或者分位數(shù)-分位數(shù)( QQ)圖來檢驗。此處的直線型圖形支持了該模型中隨機項是正態(tài)分布的假設(shè)
7、。hist(rstudent(hours.lm),xlab='Standardized Residuals')標準殘差的直方圖(季節(jié)均值模型的標準殘差直方圖)Histogram of rstudent(hours.lm)Standardized Residualsshapiro.test(rstudent(hours.lm)正態(tài)性檢驗( Shapiro-Wilk 檢驗)本質(zhì)是:計算殘差與相應的正態(tài)分位數(shù)之間的相關(guān)系數(shù)。 相關(guān)性越小,就越有理由否定正態(tài)性。Shapiro-Wilk normality testdata: rstudent(hours.lm)W = 0.99385,
8、 p-value = 0.9909根據(jù)上面的檢驗結(jié)果,我們不能拒絕模型的隨機項是正態(tài)分布的假設(shè)。第四章 平穩(wěn)時間序列模型124.4第五章 非平穩(wěn)時間序列模型5.1(a) ARMA (2,1) p=2,q=1,參數(shù)值和1=1 2=-0.25 1=0.1(b) IMA(2,0) p=2,d=1,q=0, 參數(shù)值和(c) ARMA(2,2) p=2,q=2, 參數(shù)值和1=0.52=-0.5 1=0.5 2=-0.255.7(a) A:AR(2) 1=0.92=0.09B:IMA(1,1) 1=0.1(b) 一個是固定的一個是不固定的。5.11(a) data(winnebago);win.graph
9、(width=6.5,height=3,pointsize=8)plot(winnebago,type='o',ylab='Winnebago Monthly Sales')時間序列圖selaSylhtnoMogaben表明公司的休閑車的銷量在逐漸增加。(b) plot(log(winnebago),type='o',ylab='Log(Monthly Sales)')取對數(shù)之后的時間序列圖仍然呈現(xiàn)增加的趨勢,但是比沒有取對數(shù)之前增加的緩慢一些。(c) percentage=na.omit(winnebago -zlag(winn
10、ebago)/zlag(winnebago) win.graph(width=3,height=3,pointsize=8) plot(x=diff(log(winnebago) -1,y=percentage -1,ylab='PercentageChange',xlab='Difference of Logs')cor(diff(log(winnebago) -1,percentage -1)1 0.9646886Difference of Logs5.1 0.1 5.0 0.0 5.0egnahCegatnecreP結(jié)果顯示: 0.96 認為一致。第六章
11、模型識別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)2.01.00.01.02.0FCA(b) acf(series)Series seriesLag第八章 模型診斷8.7(a) data
12、(hare);model=arima(sqrt(hare),order=c(3,0,0)win.graph(width=6.5,height=3,pointsize=8);acf(rstandard(model)殘差的樣本自相關(guān)圖Series rstandard(model)1412101.01.03.0FCA(b) LB.test(model,lag=9)Box-Ljung testdata: residuals from modelX-squared = 6.2475, df = 6, p-value = 0.396 JB統(tǒng)計量結(jié)果表明不拒絕誤差項的獨立性。(c) 對殘差進行檢驗。runs
13、(rstandard(model)$pvalue1 0.602$observed.runs1 18$expected.runs1 16.09677$n11 13$n21 18$k 1 0P 值為 0.602,不拒絕誤差項的獨立性。(d) win.graph(width=3,height=3,pointsize=8)qqnorm(residuals(model)殘差的正態(tài) QQ 圖selitnauQelpmaSNormal Q-Q Plot-1 0 1Theoretical Quantiles2QQ 圖看出有一點小的曲率,但是這種現(xiàn)象可能是倆個極端值造成的。(e)對殘差的正態(tài)性進行 shapir
14、o-wilk 檢驗shapiro.test(residuals(model)Shapiro-Wilk normality testdata: residuals(model)W = 0.93509, p-value = 0.06043結(jié)果表明,我們不會拒絕通常意義水平的正態(tài)性。第九章 預測9.2(a) Y 2007 (1) 5 1.1Y2007 0.5Y2006 5 1.1(10) 0.5(11) 10.5所以, Y 2007(2)5 1.1Y2008 0.5Y2007 5 1.1(10.5) 0.5(10) 11.55(b)從上式中看出 1 1.1 ,1 - 1 0 0, 0 1, 11.1
15、(c) Y2007 (1) 2 210.5 2 2 10.5 2.83 即 2008 年 預測的 95%預測 極限 為7.67-13.33.(d)因為有, Yt 1 (t) Yt1(t 1) t Yt 1 Yt(1)所以, Y 2008(1) Y 2007 (2) 1 Y2008 Y 2007(1) 11.55 1.112 10.5 13.2第十章 季節(jié)模型10.12(a) data(boardings);series=boardings,1 plot(series,type='l',ylab='Light Rail&Bus Boardings') po
16、ints(series,x=time(series),pch=as.vector(season(series)roda.21suB.55uB.52liB&1itaR.05th21ihLg1ONFMJ(b) acf(as.vector(series),ci.type='ma')JFAMAONFMNJFMMAA JJ D2001 2002 2003 2004 2005 2006TimeSeries as.vector(series)Lag滯后期為 1,5, 6, 12 ,時候,存在顯著的自相關(guān)。(c) model=arima(series,order=c(0,0,3),se
17、asonal=list(order=c(1,0,0),period=12);modelCall: arima(x = series, order = c(0, 0, 3), seasonal = list(order = c(1, 0, 0), period = 12)Coefficients:ma1ma2ma3sar1intercept0.72900.61160.29500.877612.5455s.e. 0.11860.11720.11180.05070.0354sigma2 estimated as 0.0006542: log likelihood = 143.54, aic = -2
18、77.09 所有的變量都是顯著的。(d) model2=arima(series,order=c(0,0,4),seasonal=list(order=c(1,0,0),period=12);model2 Call:arima(x = series, order = c(0, 0, 4), seasonal = list(order = c(1, 0, 0), period = 12) Coefficients:ma1ma2ma3ma4sar1intercept0.72770.66860.42440.14140.891812.5459s.e. 0.12120.13270.16810.12280
19、.04450.0419sigma2 estimated as 0.0006279: log likelihood = 144.22, aic = -276.45模型 2 中 AIC=-276.45,模型 1 中的 AIC= -277.09,AIC越小越好,所以模型是過度擬合的。 第十二章 異方差時間序列模型12.1 library(TSA)data(CREF)r.cref=diff(log(CREF)*100win.graph(width = 4.875,height = 2.5,pointsize = 8)plot(abs(r.cref)win.graph(width = 4.875,hei
20、ght = 2.5,pointsize = 8)plot(r.cref2)12.9(a) > data(google)> plot(google)收益率數(shù)據(jù)的時間序列圖> acf(google)> pacf(google)根據(jù) ACF和 PACF可以得知,無自相關(guān)。(b) 計算 google 日收益率均值。> t.test(google,alternative = 'greater')One Sample t-testdata: googlet = 2.5689, df = 520, p -value = 0.00524alternative hy
21、pothesis: true mean is greater than 095 percent confidence interval:0.000962967 Inf sample estimates:mean of x 0.002685589x的均值為 0.002685589 ,備擇假設(shè)為: 均值異于 0,根據(jù) P值顯示, 0.00524 接受備擇假設(shè)。(c)McLeod-Li 檢驗 ARCH效應。> win.graph(width = 4.875,height = 3,pointsize = 8) > McLeod.Li.test(y=google)根據(jù)圖顯示,所有滯后值在 5
22、%的水平上均顯著。說明數(shù)據(jù)具有ARCH特征。(d) 識別 GARCH模型,估計識別的模型并對擬合的模型進行模型診斷檢驗。> eacf(google2) 取值平方的樣本 EACF AR/MA0 1 2 3 4 5 6 7 8 9 10 11 12 13 0 x x o o o o o o o x o o o x 1 x o o o o o o o o x o o o x 2 x o o o o o o o o x o o o x 3 x x x o o o o o o x o o o x 4 x x x o o o o o o o o o o o 5 x x x o o o o o o o
23、 o o o o 6 x x x x o o o o o o o o o o 7 o x x o o x o o o o o o o o> eacf(abs(google) 絕對值的樣本 EACF AR/MA0 1 2 3 4 5 6 7 8 9 10 11 12 13 0 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
24、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根據(jù)上圖, 得知設(shè)定 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.46
25、486 0.08232 0.65379 5.73937Coefficient(s):Estimate Std. Error t value Pr(>|t|)a0 5.058e-051.232e-054.106 4.03e-05 *a1 1.264e-012.136e-025.920 3.21e-09 *b1 7.865e-013.578e-0221.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 < 2.2e-16Box-Lj
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 綜合校準系統(tǒng)戰(zhàn)略市場規(guī)劃報告
- 《生物化學》課程標準
- 冷庫貨物儲存合同范本
- 辦公材料訂購合同范本
- 化工空調(diào)采購合同范本
- 個人自我反省檢討書
- 個人工作犯錯檢討書
- 口腔治療合同范本
- 單位承包小區(qū)合同范例
- 養(yǎng)生館招募合伙人合同范本
- 地理-浙江省強基聯(lián)盟2025年2月高三年級聯(lián)考試題和答案
- 2025《醫(yī)藥企業(yè)防范商業(yè)賄賂風險合規(guī)指引》解讀課件
- 血透病人皮膚瘙癢課件
- 2025年度船舶焊接維修工程合同范本資料下載
- 貴州茅臺課程設(shè)計
- 工業(yè)攝像頭知識培訓課件
- 2024-2025學年六年級數(shù)學人教版上冊寒假作業(yè)(綜合基礎(chǔ)復習篇含答案)
- DB33T 1134-2017 靜鉆根植樁基礎(chǔ)技術(shù)規(guī)程
- 樓梯塑料滴水線施工方案
- 中華人民共和國建筑法
- 2024年濟南護理職業(yè)學院高職單招(英語/數(shù)學/語文)筆試歷年參考題庫含答案解析
評論
0/150
提交評論