自己回帰モデル/AR(Auto Regressive Model)

Equation
自己回帰モデル(n次)
y_{t}=c+a_{1}y_{t-1}+a_{2}y_{t-2}+\cdots+a_{n}y_{t-n}+\varepsilon_{t}
c=\hat{c}+E(y_{t})(1-\sum^{n}_{i=1}a_{i})

R
サンプル:2011年3月7日から2014年3月7日におけるオーストラリアドルの対日本円レート
audjpyaudjpypointaudjpyresidualqqplot

> library(tseries)
> armodel <- ar(dataset$AUD,method="ols")
> armodel

Call:
ar(x = dataset$AUD, method = "ols")

Coefficients:
      1        2        3        4        5        6        7        8  
 0.9580   0.0885  -0.0575   0.0421  -0.0068   0.0104  -0.1481   0.0810  
      9       10       11       12       13       14       15       16  
 0.0299   0.0292   0.0139  -0.0814   0.0584  -0.1106   0.1147  -0.0489  
     17       18       19       20  
 0.0083   0.0715   0.0099  -0.0688  

Intercept: 0.008025 (0.02823) 

Order selected 20  sigma^2 estimated as  0.5701

> armodel$x.mean
[1] 86.98142

> armodel$resid
  [1]            NA            NA            NA            NA            NA
  [6]            NA            NA            NA            NA            NA
 [11]            NA            NA            NA            NA            NA
 [16]            NA            NA            NA            NA            NA
 [21] -0.4869880272  0.6635418596  0.7602972180  0.4393316614  0.5436386949
 [26] -1.3866992210  0.1205900044 -0.3431626027  0.3954356314 -0.5442442929
 [31] -0.9037411846  0.9829152326  0.5471737873 -0.3852546852  0.3494755055
 [36] -1.0608793219  0.6343525712  1.3300340595 -0.3827268569 -3.6725115868
 [41]  0.8866514391 -0.0768655838  1.1372947178 -0.8911878416 -0.2408049875
 [46] -0.7866740146 -0.1127700729  0.7210546822  0.7340963299  0.4396079199
 [51] -0.3009827043 -0.9288700742  0.1006697723 -0.1069806476  0.1322662964
 [56] -0.0677192106  0.5068524901  0.1149261651 -0.8745545214  0.2687731806
 [61] -0.0765242017 -0.4043175848 -0.2648625221 -0.2482878286  0.2867836933
 [66] -0.7259112384 -0.1661605222  1.1197297782 -0.3598865573 -0.3585028919
 [71] -0.2875758156 -0.0001154293 -0.0521050250 -0.1168565189  0.0696177478
 [76] -0.6831327235  0.1453679545  0.8977245802  0.9475289011  0.1100475186
 [81]  0.4883967279 -0.1671151773 -0.3793903947 -0.0088150044  1.0600167187
 [86] -1.2012746090 -1.0886366455 -0.7556470157  0.2601043360  0.1826490502
 [91] -0.8989697341  1.1934023912 -0.2361251596  0.2499868702 -0.3851890884
 [96] -0.1057058724  0.5983341166  0.5135635029 -0.3899493354  0.1083538453
[101] -0.6259670627 -2.2831609430 -0.3740548699 -0.1307658286 -1.2043072121
[106] -2.8142724674  1.3279719397 -0.8698808604  0.5421650249  0.8849400736
[111]  0.1637400813 -0.0677838216 -0.0565616196 -1.0055768675 -0.1273270763
[116]  0.0437365079  0.9368450094 -0.2834255544  0.6433591937 -0.1540137724
[121]  0.9459483709 -0.4784249765  0.4737414114  0.6591625788 -1.2182700247
[126] -0.3724174496  0.6503164901  0.5418718220 -0.0363007325 -1.7393418155
[131] -0.9652956737 -0.1305548152 -0.8427590172  0.1955314995 -0.7747452184
[136]  0.1640759025 -1.3787215099 -2.4652651537 -0.4474129879  0.8550290266
[141] -0.9880618486  0.5394779820 -0.3074953550 -1.9974503892 -0.2304263192
[146]  1.0409990275  0.5074750785  1.9094630975 -0.2656451094  2.5812773533
[151] -0.8724551549  1.1112334796 -1.3223607034  0.2852680266  0.2516194113
[156] -0.1423372031  0.6739670691  0.4248859000 -0.6553270257  0.2776262480
[161]  1.8281987724 -0.0675164705  1.4211142573 -1.6517772005  0.0789042781
[166]  0.0714002119 -0.8229056804  0.0333462667 -2.1389611112 -0.1467388847
[171]  0.7133251819 -0.6261785577 -0.7490609458 -0.7789251445 -0.2101492849
[176] -0.8473397129 -0.5954662292 -1.1523166261  0.1352590102  1.1125935409
[181]  0.8224984886  1.1671669978  0.7136604034  0.1120830749  0.1309644225
[186] -0.4077200016  0.0677272214  0.0456337380 -0.5231366188 -0.1672535129
[191] -0.6172556540 -0.4697468222 -0.8215066038  0.2029436556  0.0758216833
[196]  0.1529740138  1.3863703996 -0.0599970010  0.1728052358 -0.1966299088
[201] -0.4825015187 -0.7259967936  0.5030535434  0.4325189349 -0.1437281343
[206] -0.1940801238 -0.4442491698  0.1395182927  0.0952168856  0.1125534780
[211] -0.3001864703  0.5489790092  0.2920431577 -0.0426093404  0.3552998715
[216]  0.1226747589  0.4752927193  0.5577328809  0.5803920315 -0.3820849183
[221] -0.6735674467 -0.4461889218 -0.4198055791  0.9725327818 -0.0698317101
[226]  0.6272986806 -0.1660507192  0.7233819427 -0.0690009818  0.4561743673
[231] -0.3814651569 -0.0424717148  0.8446743649  0.1206242562  0.6861265704
[236]  0.8798223321 -0.4660042527 -0.5538981439  0.0453341222  0.8136803099
[241]  0.7575279816 -0.1293136674  0.6763929296  0.0906342129  0.3457972561
[246] -0.3825682220 -0.4229060064 -2.1800206047  0.8211964177  1.2043371954
[251] -0.0933545994 -0.0732480857  0.9156499659 -0.0730785693 -0.0902948779
[256]  0.6296078910 -0.4468302799 -0.5341064339 -1.3036442139  0.4233015939
[261]  0.7290473465 -0.8580317353 -0.6693780727 -0.5239323791  1.3091871900
[266] -1.3552453461  0.2080758072 -0.5890531076  0.0596404272 -1.1202820179
[271]  0.3439533412 -1.3975327424  0.4936497811  1.1857160254 -1.1090605379
[276] -0.2884181712  1.1746847147  0.0683830603 -0.2158484313 -0.0924905662
[281] -0.3784529288  0.0581572494  0.2154540498 -0.1782172139 -0.7789853012
[286] -0.4242261738 -2.0367226864  0.6348692126 -0.8517799295 -0.4101035098
[291]  0.6559282950 -0.3738230414 -0.7864540192  0.0376521136 -0.1484696453
[296] -1.5351318485 -0.3930353661  0.7306129594 -0.7369946362 -0.5729297245
[301]  0.1270471751  0.3552764052 -0.2195325995 -0.1238307330 -1.3665241772
[306] -0.2460952689 -1.1461021674  1.0401337865  0.6940815639  1.3929238189
[311]  0.3733044338  0.4981002356 -1.2750764504  0.4564965457  0.0662024006
[316]  0.4859870564  0.8604584376 -0.1540277716  0.1632526708  0.4529138130
[321] -0.6514735419  0.0535675747 -0.7291946398  0.2358524286  0.5337218926
[326] -0.6603349745  1.7473603413 -0.0569714238  0.1741758372 -0.0177757289
[331] -0.0538411663 -1.0767610183 -0.2411116448 -0.0597287934  0.5780002541
[336] -1.0224637694  0.3525663235  0.6290510391 -0.0941203744  0.1036743528
[341] -0.7829055792 -0.5589650450 -0.8324541862  0.7129872949  1.0164363209
[346]  0.4857665520  0.0835774979 -0.4309924859 -0.0643788180 -0.5288630140
[351]  1.3506442588 -0.1707160443  0.2369798675  0.1197682502  0.0087757476
[356] -0.6575554620 -0.3060017669  0.2385449783  0.5151178260  0.4581805549
[361] -0.3284180048 -0.1607080223 -0.1349068042 -0.6852266896 -0.5627024608
[366]  0.0558125586 -0.4265057825 -0.0835466073 -0.2542040270 -0.5451235969
[371] -0.6583643293 -0.1990493886  0.0454821444 -0.2409845399  1.1890138527
[376] -0.0433596198 -0.3818963706  0.3433816233 -0.0029893587  0.4074934098
[381]  0.1625984221  0.0340257215 -0.0620049857 -0.2175948688 -0.4413325361
[386] -0.4827069139 -0.4184741097 -0.1434673961  0.6624476416 -0.3093607017
[391]  0.0057043145 -0.5074858426 -0.1963834328  0.1499249647 -0.4804190555
[396] -0.2477431762  0.3195060425  0.3644677781 -0.8244867867  0.7116418005
[401]  0.4060997389  0.8006400063  0.3089293510 -0.6916628791  0.7667356184
[406] -0.4198760598  0.5374164252  0.2914909378 -0.6569585343  0.1628970972
[411]  0.0718194223  0.1981038076  0.4046613682  0.0454603829 -0.1585245437
[416]  0.2545060231 -0.1914672773 -0.9018828186 -0.0125683788  0.2700597197
[421]  0.0408167111 -0.0091967652  0.7492191883  0.5263644669  0.1872614829
[426]  0.1464248299  0.5952947289  0.8681240707 -0.5106308106 -0.1528841768
[431] -0.0016941604 -0.3718475499 -0.0133302928 -0.0816476683  0.2822854271
[436]  0.5352752371  0.2687481918 -0.0075931616 -0.2420529948  0.6389972999
[441]  0.9390209037  0.0665854686  0.4660482389 -0.0138787989  0.0898969203
[446] -0.7026580224  0.0842041392 -0.4852208528  0.6361086455  0.6347782585
[451]  0.8607861616  1.9419607757  0.6178513401 -0.4505669384 -0.6256598530
[456]  1.0662606673  1.9891047800  0.2113075345 -0.8829774497 -0.1469117577
[461]  1.2230486260 -0.7878014386  0.0343311991 -0.3527724437 -0.2103285711
[466]  1.4367682236  0.1563958759 -0.3734787413  0.6249329499  0.0276324423
[471]  0.5968529667  0.5411352610  0.1632783988  0.7604997313 -0.7175026581
[476] -0.4970443411  0.5436459852  0.0212957453  0.1724445169 -0.4053252797
[481]  0.3767271774  0.3636152202  0.1888612869 -0.6292328746 -0.4045230926
[486]  1.1025287567 -1.5465821831 -1.0811951780  0.7186204771 -0.0869276728
[491]  0.6788489735 -0.0796571782  0.5797539052  0.4976600617  1.1112386950
[496]  0.7795385481  0.9865848584  0.1997357312  0.2921669915  0.2938134049
[501] -1.6020142598  1.1116462777  0.5465455526 -0.3866951989 -0.0242716059
[506] -0.3694088458  0.8452608338 -0.6103202072 -0.6292038863  0.4916366239
[511] -0.7249059757  0.6483462208 -0.6634964095  3.6603555038  1.2262864794
[516]  1.3321838071  0.4975788372  0.8327751661  0.1382530482 -1.5254705235
[521] -3.4158090065  1.7577477376 -0.5600095370  0.4439536941  1.4974095593
[526] -0.2890744454  0.3186714758  0.0909161553 -0.1177008640 -0.6339057246
[531] -0.2581426122 -0.7107460567  1.2679945555 -0.7847799462 -0.3244271693
[536]  1.2730376379 -0.1698308605 -0.4408828078  0.2804348984  0.3377113934
[541] -0.6492591125 -0.1480290211  0.0989698110  0.2453612118 -0.4231691708
[546] -1.0503330614 -1.7372194482  0.4344479951  0.4706784348 -0.2793041280
[551]  0.8175921748 -1.1599872983  0.2885935672 -0.5528916364 -2.5543864413
[556] -1.0037142308 -0.4779274555  0.9838083443 -1.7071475880 -1.0221536249
[561]  0.5198600781  0.0131436175 -0.2630583825 -0.4202684321 -0.0622118738
[566] -0.1591200233  1.1803516876 -0.4155045832  0.3571960720 -0.0074029963
[571]  0.3435376965 -0.2760024751  1.0439365264  0.5441956851 -1.1206828724
[576]  0.8754460307 -0.0507940264  0.4607507444  0.6899817192 -0.7861381949
[581] -0.9577299361  0.2682949248  0.8009724724  0.1090112460  0.5936846201
[586] -0.1175845738 -0.1476137146  0.2339923075 -0.7881545311  0.2320032537
[591] -0.9975850385 -0.6272932894 -1.5280392607 -0.9900122305  1.3225565526
[596] -0.7480866737 -0.7295504440 -0.0130453514  0.0724083499  0.8222596812
[601]  0.0686532850  0.4899427583  0.5375019971  0.3958616128 -0.9730141658
[606]  0.6487198581 -0.5462039521 -0.9763470208 -0.4237524808  1.6543511405
[611]  0.0852957705 -0.8691712664 -1.0782789416  0.5514781120  0.2243593340
[616]  0.2051576765  2.1274647075  0.4062099768  0.9805367984 -0.1493491036
[621] -0.1646171239  0.6635176162  1.2032203517  0.1377393620 -1.0073151374
[626]  0.1305817815  0.3679065447  0.4731069965  0.8307780581 -1.0372907516
[631]  0.1427022276 -0.6272084860  0.4841289984 -1.7674094492  0.6801041699
[636]  0.7707278611 -0.8924084878  0.1602113861  0.1390811574 -0.3929063044
[641] -0.0119431358  0.7050701062  0.8944840312  0.8682311245  0.1739196049
[646]  0.3028954165  0.0247365636 -0.0575364537  0.3990579822  0.8741837222
[651] -1.4957674616 -0.5825762441  0.5966973574 -0.9740469746  0.2061453217
[656]  0.7605392488 -0.4910995747  0.8534924366 -0.1929303703 -0.0972507015
[661] -0.8401511502  0.0692662007  0.0251710601 -0.1901814602  0.5058289988
[666]  0.3331354144  0.5370739278 -0.4960313551  0.7690938693 -0.4106148721
[671] -0.3586271874 -0.0377415688  0.0822898955 -0.6790924222  0.3878289735
[676]  0.2732407933  0.3179313142  0.3738759858 -0.6875852862 -0.5176552275
[681] -0.1078241034  1.5179248468  0.2467155837  0.0841359875 -1.1223894934
[686] -0.4159081944 -0.3484817890 -0.2384054656 -0.1347080252  0.6526898388
[691]  0.4600114501  0.4396599562 -0.0785792961  0.3480021901 -0.1281291789
[696] -0.0203189181  0.7446391971 -0.4385352467  0.1145522705 -0.0199254935
[701] -0.2823918239  0.0879615033  0.0479908320 -0.6541153002 -0.4282570531
[706] -0.8069656653  0.8855692304  0.5510648792  0.1663909967 -1.8882886770
[711] -1.7167879008  0.8434034374  0.7997029837 -1.2773314241  1.4719929163
[716] -0.7781856150 -1.4599568126  1.6268726468  0.8509585220  0.4056373511
[721]  0.3803969140  0.8804107115 -0.7748845569 -0.0868475149 -0.0864863728
[726]  0.9129457986 -0.2937191737 -0.2071367265  0.6248864391 -0.3490806472
[731]  0.4382828437 -0.5531771499 -0.4035055485 -0.0251200092 -1.0795965092
[736]  0.7929287626  0.8084907391  0.7655492927  1.0435626705

> plot(dataset$AUD,type="l",main="AUD/JPY.2011/3/7-2014/3/7",ylab="AUDJPY",xlab="dataNo.")
> points(dataset$AUD-armodel$resid)
> qqnorm(armodel$resid)
> qqline(armodel$resid)

> jarque.bera.test(armodel$resid[21:739])

        Jarque Bera Test

data:  armodel$resid[21:739]
X-squared = 169.0488, df = 2, p-value < 2.2e-16

> Box.test(armodel$resid[21:739],lag=30,type="Ljung")

        Box-Ljung test

data:  armodel$resid[21:739]
X-squared = 13.7242, df = 30, p-value = 0.9952

参考文献
大崎秀一,吉川大介(2013).『ファイナンスのためのRプログラミング』.共立出版.179pp.
福地純一郎、伊藤有希(2011).『Rによる計量経済分析』.朝倉書店.186pp.

アプリケーション
R Core Team (2013). R: A language and environment for statistical computing.
R Foundation for Statistical Computing, Vienna, Austria.
URL http://www.R-project.org/.