8時間序列回歸模型_第1頁
8時間序列回歸模型_第2頁
8時間序列回歸模型_第3頁
已閱讀5頁,還剩15頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、時間序列回歸模型1 干預(yù)分析1.1 概念及模型Box 和 Tiao 引入的干預(yù)分析提供了對于干預(yù)影響時間序列的效果進行評估的一個框架,假 設(shè)干預(yù)是可以通過時間序列的均值函數(shù)或者趨勢而對過程施加影響, 干預(yù)可以自然產(chǎn)生也可 以人為施加的,如國家的宏觀調(diào)控等。其模型可以如下表示:其中mt代表均值的變化, Nt是ARIMA過程。1.2 干預(yù)的分類階梯響應(yīng)干預(yù)脈沖響應(yīng)干預(yù)1.3干預(yù)的實例分析模型初探對數(shù)化航空客運里程的干預(yù)模型的估計> data(airmiles)> acf(as.vector(diff(diff(wi ndow(log(airmiles),e nd=c(2001,8),1

2、2),lag.max=48)#用window得到在911事件以前的未愛干預(yù)的時間序列子集Cm對暫用的模型進行診斷>fitmode<-arima(airmiles,order=c(0,1,1),seas on al=list(order=c(0,1,0)> tsdiag(fitmode)從診斷圖可以看出存在三個異常點,acf在12階存在高度相關(guān)因此在季節(jié)中加入MA( 1)系數(shù)。擬合帶有干預(yù)信息的模型函數(shù):arimax(x, order = c(0, 0, 0), seas onal = list(order = c(0, 0, 0), period=NA),xreg = NUL

3、L, i nclude.mea n = TRUE, tran sform.pars = TRUE, fixed = NULL,init = NULL, method = c("CSS-ML", "ML", "CSS"), n.cond, optim.control =list(),kappa = 1e+06, io = NULL, xtransf, transfer = NULL)arimax 函數(shù)擴展了 arima 函數(shù),可以處理時間序列中干擾分析及異常值。假設(shè)干擾影響過 程的均值,相對未受干擾的無價值函數(shù)的偏離用一些協(xié)變量的ARM

4、A濾波器的輸出這種來表示,偏差被稱作傳遞函數(shù)。 構(gòu)造傳遞函數(shù)的協(xié)變量通過 xtransf 參數(shù)以矩陣或者 data.frame 的形式代入 arimax 函數(shù)。air.m1=arimax(log(airmiles),order=c(0,1,1),seasonal=list(order=c(0,1,1), period=12),xtransf=data.frame(I911=1*(seq(airmiles)=69),I911=1*(seq(airmiles)=69), transfer=list(c(0,0),c(1,0),xreg=data.frame(Dec96=1*(seq(airmile

5、s)=12), Jan97=1*(seq(airmiles)=13),Dec02=1*(seq(airmiles)=84),method='ML')> air.m1Call: arimax(x = log(airmiles), order = c(0, 1, 1), seasonal = list(order = c(0, 1,1), period = 12), xreg = data.frame(Dec96 = 1 * (seq(airmiles) = 12), Jan97 = 1 *(seq(airmiles) = 13), Dec02 = 1 * (seq(airm

6、iles) = 84), method = "ML",xtransf = data.frame(I911 = 1 * (seq(airmiles) = 69), I911 = 1 * (seq(airmiles)69), transfer = list(c(0, 0), c(1, 0)Coefficients: ma1I911.1-MA0sma1Dec96Jan97Dec02I911-MA0I911.1-AR1-0.3825-0.64990.0989-0.06900.0810-0.09490.8139-0.2715s.e.0.09260.11890.02280.02180.

7、02020.04620.09780.0439sigmaA2 estimated as 0.0006721: log likelihood = 219.99, aic = -423.98 畫圖plot(log(airmiles),ylab="log(airmiles)") points(fitted(air.m1)2ood2W4Timepl-" 竹民 L 理匚Nin e11p=1*(seq(airmiles)=69)plot(ts(Ni ne11p*(-0.0949)+filter(Nin e11p,filter=.8139,method='recursiv

8、e',side=1)*(-0.2715),frequen cy=12,start=1996),type='h',ylab='9/11 Effects')abli ne(h=0)I9M!1!HBJDOO30022CMMThb從上圖可以看出在2003年底后,911事件的影響效應(yīng)才平息,航班客運量恢復(fù)了正常。2異常值A(chǔ)O 和 10。在時間序列中異常有兩種,可加異常和新息異常,分別記2.1異常值示例模擬數(shù)據(jù)模擬一般的ARIMA( 1 , 0, 1),然后故意將第10個觀測值變成異常值 10.> set.seed(12345)> y=arima.sim

9、(model=list(ar=0.8,ma=0.5), n. start=158 ,n=100)> yTime Series:Start = 1End = 100Freque ncy = 11 0.49180881 -0.22323665 -0.99151270 -0.73387818 -0.67750094-1.14472133 -2.14844671 -2.495307949 -1.50355358 -2.12615253 -0.55651713 0.41326344 0.518691291.86210605 2.19935472 2.6021016517 0.79130003 0.

10、26265426 2.93414857 3.99045889 3.608226781.17845765 -0.87682948 -1.2063779925 -1.39501221 -0.18832171 1.22999827 1.46814850 2.666474913.23417469 2.60349624 1.4951321533 1.48852142 0.95739219 1.30011654 1.73444053 2.848251033.73214655 4.23579456 3.3704979041 2.02783955 1.41218929 -0.29974176 -1.58712

11、591 -1.340808780.10747609 1.44651081 1.6780948749 -0.34663129 -0.50291459 0.01739605 -0.01426474 0.942172040.39046221 -0.39883530 1.6063891857 1.70668201 1.37518194 1.91824534 0.14254056 -2.88169481-3.30372327 -1.74068408 -3.2486805765 -3.89415683 -3.45920240 -1.11042078 0.67959744 0.670510840.44394

12、061 1.89536060 2.3606387373 2.00559443 0.86443324 0.46847572 0.72338498 1.602150981.25922277 1.53180859 0.9628977981 1.07712188 1.42386354 0.56318008 -0.46689543 -0.91861106-1.92947085 -2.18188785 -1.0275908789 2.31088272 3.13847319 3.01237881 3.43454807 2.315394942.44909873 2.91589141 1.1264890897

13、-0.08123871 0.44412579 0.26116418 -0.45815484> y10<-10模型初步判斷> acf(y)stnet vw _5101520Lag> pacf(y)V40 s-*!1 «g¥>n> eacf(y) AR/MA0 1 2 3 4 5 6 7 8 9 10 11 12 130 x x o o o o o o o o o o o o1 o o o o o o o o o o o o o o2 o o o o o o ooo o oooo3 o x o o o o ooo o oooo4 o x o

14、o o o ooo o oooo5 x x o o o o ooo o oooo6 x o o o o o ooo o oooo7 o x o o o o ooo o oooo從三個的結(jié)果來看,可以初步分析y是AR (1)模型對模型時行擬合> m1=arima(y,order=c(1,0,0)> m1Call:arima(x = y, order = c(1, 0, 0)Coefficie nts:ar1 in tercept0.54190.7096s.e. 0.08310.3603對模擬模型進行異常值探測> detectAO(m1),1,2,3ind 9.000000 10

15、.000000 11.000000Iambda2 -4.018412 9.068982 -4.247367> detectAO(m1,robust=F),1ind 10.000000lambda2 7.321709> detectlO(m1),1 ,2ind 10.000000 11.00000lambda1 7.782013 -4.67421AO探測結(jié)果認為第 9, 10, 11.可能出現(xiàn)異常值。10探測認為第10, 11可能出現(xiàn)了異常值。 由于檢驗統(tǒng)計量的最大取值出現(xiàn)在10且AO 10,所以更認為出現(xiàn)異常值在第10是AO異??紤]異常值的時間序列擬合> m2=arima(y

16、,order=c(1,0,0),xreg=data.frame(AO=seq(y)=10)> m2Call:arima(x = y, order = c(1, 0, 0), xreg = data.frame(AO = seq(y) = 10)Coefficie nts:ar1 in terceptAO0.80720.5698 10.9940s.e. 0.05700.5129 0.8012sigmaA2 estimated as 1.059: log likelihood = -145.29, aic = 296.58> detectAO(m2)1 "No AO dete

17、cted"> detectIO(m2)1 "No IO detected"比較有無異常值的兩模型再次進行異常值探測時,沒有發(fā)現(xiàn)異常值,驗證最初序列異常出現(xiàn)在10的猜測對比模型1和2的擬合效果> tsdiag(m2)雖然模型二的殘差通過引入異常值后正太性是顯性的,但是其acf和P值結(jié)果顯示引入 MA(1)是必要的。重新擬合適當(dāng)模型> m3=arima(y,order=c(1,0,1),xreg=data.frame(AO=seq(y)=10)> detectAO(m3)1 "No AOdetected"> detec

18、tIO(m3)1 "No IO detected"> tsdiag(m3)Call:arima(x = y, order = c(1, 0, 1), xreg = data.frame(AO = seq(y) = 10)Coefficie nts:ar1 ma1 in tercept AO0.6596 0.61540.5850 11.1781s.e. 0.0799 0.07960.4132 0.4755sigmaA2 estimated as 0.793: log likelihood = -131.16, aic = 270.33II1*JD模型的擬合效果是顯著提高

19、。Acf和P值檢驗也一步通過。> plot(y,type='b')> arrows(40,7,11,9.8,le ngth=0.8,a ngle=30)2.2另一個現(xiàn)實例子數(shù)據(jù)包中的co2>m1.co2=arima(co2,order=c(0,1,1),seas on al=list(order=c(0,1,1),period=12)> m1.co2Call:arima(x = co2, order = c(0, 1,1), seas onal = list(order = c(0, 1, 1), period = 12)Coefficie nts:ma

20、1 sma1-0.5792 -0.8206s.e. 0.0791 0.1137sigmaA2 estimated as 0.5446: log likelihood = -139.54, aic = 283.08> detectAO(m1.co2)1 "No AO detected"> detectIO(m1.co2),1ind 57.000000lambda1 3.752715擬合含有新息異常的模型>m4.co2=arimax(co2,order=c(0,1,1),seas on al=list(order=c(0,1,1),period= 12),io

21、=c(57)> m4.co2Call:arimax(x = co2, order = c(0, 1, 1), seas onal = list(order = c(0, 1,1), period = 12),io = c(57)Coefficie nts:ma1 sma1 10-57-0.5925 -0.8274 2.6770s.e. 0.0775 0.1016 0.7246 sigmaA2 estimated as 0.4869: log likelihood = -133.08, aic = 272.16模型顯示AIC相比之前模型一更小了。而且10效應(yīng)的P值=2.677/0.7246

22、 是顯著的.3偽相關(guān)在時間序列中引入?yún)f(xié)變量,如非洲牧草產(chǎn)量通常與某些氣候指標(biāo)密切相關(guān),在這種發(fā)問下在通過在時間序列模型中納入相關(guān)的協(xié)變量,將有助于更好的了解基礎(chǔ)過程以及得到更為準(zhǔn)確的預(yù)測。3.1模擬數(shù)據(jù)set.seed(12345)X=rnorm(105)Y=zlag(X,2)+.5*rnorm(105)X=ts(X-(1:5),start=1,freq=1)Y=ts(Y-(1:5),start=1,freq=1)ccf(X,Y,ylab='CCF')Leg3.2奶產(chǎn)量與對數(shù)化發(fā)電量的偽相關(guān)data(milk)data(electricity)milk.electricity=

23、ts.i ntersect(milk,log(electricity)# 列合并在一個容器中。intersect 函數(shù)將多個時間序1094199&T99820002GD220042D06Tinwrnilk.eiettriciryrntDMr£oFLIm-±gccf(as.nu meric(milk.electricity,1),as .nu meric(milk.electricity,2), mai n='milk & electricity',ylab='CCF')milk & 曲euEcvtyLag兩者相關(guān)性似乎

24、非常的強,但實際上這是因為他們的各自存在很強的自相關(guān)性。4預(yù)白化與隨機回歸對于具有強自相關(guān)的數(shù)據(jù)而言,很難評估兩個過程之前是否存在依賴關(guān)系,因而,宜將x和y之間的線性關(guān)系關(guān)聯(lián)從其各自相關(guān)關(guān)系中剝離出來。預(yù)白化正是為了達到此目的的一個有效工具。4.1牛奶與電量的CCF預(yù)白化校正再次分析兩者的相關(guān)性,此時除了時滯-3具有邊緣顯著外,其他地方?jīng)]有一個相關(guān)系數(shù)是顯著的。幌動防震 這給出的35個樣本互相關(guān)系婁中大約會出現(xiàn)1.75=35x0.05個虛假警報,即這個-3系數(shù)的顯著可能就是一個虛假的信息。因此,牛奶與耗電量序列實際上是基本不 相關(guān)的。從而認為之前在原始數(shù)據(jù)序列中發(fā)現(xiàn)的強互相關(guān)是偽相關(guān)的。4.2

25、 Log (銷售量)與價格數(shù)據(jù)的相關(guān)性分析預(yù)白化處理ULn-blrd口2D«UMlin預(yù)白化處理prewhite n(y=diff(bluebird),1,x=diff(bluebird),2,ylab='ccf)從CCF圖可以看出兩者之間只在時滯 0處是顯著的。即價格與銷售量之間存在著很強的同期 負相關(guān)關(guān)系。即當(dāng)期提高價格將導(dǎo)致銷售量的當(dāng)期下降。4.2.2 一般線性回歸分析> sales=bluebird,1> price=bluebird,2> chip.m1=lm(salesprice)> summary(chip.m1)Call:lm(form

26、ula = sales price)Residuals:Min 1Q Media n3Q Max-0.54950 -0.12373 0.00667 0.13136 0.45170Coefficie nts:Estimate Std. Error t value Pr(>|t|)(In tercept) price15.8900.217 73.22 <2e-16 *Sign if. codes: 00.001 ' * ' 0.01*' 0.050.1Residual sta ndard error: 0.188 on 102 degrees of freedo

27、mMultiple R-squared: 0.7926,Adjusted R-squared: 0.7906F-statistic: 389.9 on 1 and 102 DF, p-value: < 2.2e-16> acf(residuals(chip.m1),ci.type='ma')由于回歸后的殘差自相關(guān)在四階是顯著的,因此我們要對其進行再一步的分析r«>idua)icriip.mi|-2.4890.126 -19.75 <2e-16 *> eacf(residuals(chip.m1)AR/MA0 1 2 3 4 5 6 7 8

28、 9 10 11 12 130 x x x x o o x x o o o o o o1 x o o x o o o o o o o o o o2 x x o x o o o o o o o o o o3 x x o x o o o o o o o o o o4 o x x o o o o o o o o o o o5 x x x o x o o o o o o o o o6 x x o x x x o o o o o o o o7 x o x o o o o o o o o o o oarma( 1,4)差的回歸模型。Eacf推薦其殘差包含一個以(1,4)為頂點為的零值三角形,從而表明其為

29、模型,因此可將對數(shù)化銷售量擬合成對于價格序列的帶有ARMA( 1, 4)誤:423模擬ARMA( 1, 4)初探> chip.m2=arima(sales,order=c(1,0,4),xreg=data.frame(price)> chip.m2Call:arima(x = sales, order = c(1,0, 4), xreg = data.frame(price)Coefficie nts:ar1 ma1 ma2 ma3 ma4 in tercept price0.1989 -0.0554 0.2521 0.0735 0.526915.7792 -2.4234s.e.

30、0.1843 0.1660 0.0865 0.1084 0.13760.2166 0.1247 sigmaA2 estimated as 0.02556: log likelihood = 42.35, aic = -70.69結(jié)果表明ma1,ma3的系數(shù)并不顯著,即可認為其系數(shù)為0調(diào)整模型>chip.m3=arima(sales,order=c(1,0,4),xreg=data.frame(price),fixed=c(NA,0,NA,0,NA,NA,NA)#第一個NA指代AR1的系數(shù),第一個 0指ma1第二個NA指的是ma2第二個0指的 是ma3的系數(shù)。第三個 na指ma4,倒數(shù)第二個na是指截距項對應(yīng)的系數(shù),最后一個na指的是price對應(yīng)的系數(shù)。> chip.m3Call:arima(x

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論