sol - GoZips.uakron.edu

advertisement
Time Series – HW3
Sample Solution
1. Read in the sunspot data directly onto your R by copy and pasting below code onto
your R console.
Y1 <read.csv("http://gozips.uakron.edu/~nmimoto/pages/datasets/sunspots.csv",
header=F)
Y <- ts(Y1, start=1770)
plot(Y,type="o")
(a) Find appropreate AR(p) model, using ACF/PACF and AIC. You can use ar()
function to automatically choose p for smallest AIC.
Fit1 <- ar(Y)
Fit1
Running ar() function with default search for p using AIC resulted in AR(2) model. demean=T
was uses as default.
(b) Estimate the AR parametes using Yule-Walker estimator in ar() function. Should
you use demean=TRUE option or not? Test each parameter for significance. If
you find any parameter to be insignificant, remove, and estimate the remaining
parameters.
> Fit1$ar
[1]
1.3175005 -0.6341215
> sqrt(Fit1$asy.var.coef)
[,1]
[,2]
[1,] 0.07850996
NaN
[2,]
NaN 0.07850996
Both parameters are significant.
(c) Plot residuals after AR fit. plot acf and pacf of the residuals. Are you satisfied
with what the plots are showing? Does your AR(p) has good fit? Hint: In R,
X[-c(1,2)] means omit first two elements in vector X.
plot(Fit1$resid[-c(1,2)], type="o")
acf(Fit1$resid[-c(1,2)])
Residual ACF shows some sign of correlation, even though not strong. PACF does show
some sign of correlation. The worst is the plot of residual showing not constant variance
across all t. AR(2) model fit is not adequate.
(d) Predict 10-year ahead, and plot the prediction, together with the original data
with approximate 95% prediction interval.
Y.h <- predict(Fit1, n.ahead=10)
ts.plot(cbind(Y,Y.h$pred,Y.h$pred+1.96*Y.h$se, Y.h$pred-1.96*Y.h$se),
type="o", col=c("black","red","blue","blue"))
abline(h=mean(Y), col="blue")
abline(h=0)
(e) Fit AR(3) to the data. Test the Y-W estimated parameters for significance.
Fit2 <- ar(Y, aic=F, order.max=3)
Fit2$ar
[1]
1.36853091 -0.74014620
0.08047413
sqrt(Fit2$asy.var.coef)
[,1]
[,2]
[,3]
[1,] 0.10173105
[2,]
NaN 0.08101021
NaN 0.1554089
[3,] 0.08101021
NaN
NaN 0.10173105
Third AR parameter is not significant. Therefore AR(2) is better.
(g) Plot residuals after AR fit. plot acf and pacf of the residuals. Are you satisfied
with what the plots are showing? Does your AR(p) has good fit? Hint: In R,
X[-c(1,2,3)] means omit first three elements in vector X.
plot(Fit1$resid,type="o")
acf(Fit1$resid[-c(1,2,3)])
pacf(Fit1$resid[-c(1,2,3)])
Residuals are very similar to that of AR(2). Not good.
(g) Using AR(3) model, predict 10-year ahead, and plot the prediction, together with
the original data with approximate 95% prediction interval.
Y.h <- predict(Fit2, n.ahead=10)
ts.plot(cbind(Y,Y.h$pred,Y.h$pred+1.96*Y.h$se, Y.h$pred-1.96*Y.h$se),
type="o", col=c("black","red","blue","blue"))
abline(h=mean(Y), col="blue")
abline(h=0)
(h) Which model is better in your mind? Your model in (a), or AR(3) in (f)? Why?
AR(2) chosen in (a) is better than AR(3), because the third parameter in AR(3) is not
significant. However, residual of AR(2) shows less than optimal characteristic. Better
model than AR(2) is needed.
(i) Output numerical values of 10 predicted points for two models. Use cbind(A,B)
to put them side by side.
> cbind(Fit1$resid, Fit2$resid)
Time Series:
Start = 1770
End = 1869
Frequency = 1
Fit1$resid Fit2$resid
1770
NA
NA
1771
NA
NA
1772
7.1522051
NA
1773 -14.8160946 -16.4221936
1774 11.8804781 11.6889340
1775 -26.5072858 -28.4938884
1776 15.5762411 16.8849667
1777 55.2298184 53.6524526
1778 30.6133592 28.6715068
1779 -34.4149268 -32.9330471
1780
3.1081209
6.8492761
1781 20.4186192 18.1368767
1782 -12.5487312 -15.8701959
1783
1.1962195
0.8222113
1784 -11.0649171 -12.4861508
1785 10.5507676 10.6167820
1786 42.8621807 42.0425606
1787 23.0073500 21.7074474
1788 -5.1370084 -3.8085794
1789 14.2524450 16.0791415
1790
2.7458304
1.1866647
1791
8.3922661
6.9641038
1792 13.9393767 11.7623849
1793 -4.4229137 -6.4279856
1794
2.2657428
2.0327978
1795 -18.0728333 -18.8145984
1796 -0.5275516
0.1613064
1797 -16.6224786 -17.3161183
1798 -8.6180807 -7.7220575
1799 -9.3242945 -8.9840870
1800 -7.5450391 -6.7652308
1801
5.1348216
6.0364396
1802 -5.7763387 -5.3945776
1803 -9.5864148 -8.2088126
1804
5.0239226
6.0603748
1805 -8.8318230 -9.1477876
1806 -11.7562124 -11.0749228
1807 -15.1159338 -14.7587379
1808 -2.2786250 -2.0043835
1809 -17.0578107 -17.4633154
1810 -12.4210505 -11.2838880
1811 -12.5907783 -11.8267551
1812 -11.1765218 -10.1927337
1813 -8.8124025 -7.7657628
1814 -13.4984203 -12.4653685
1815
9.3054291 10.6566965
1816 -6.0938392 -6.1654791
1817 -12.2697938 -10.8371973
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
-9.7069548
-4.3850564
-11.4553895
-13.7201142
-9.9355813
-13.6901730
-6.9575364
-7.1307826
3.8164415
-1.5089753
4.0943255
2.1620199
7.1839751
-17.9154196
-5.0764214
-13.3112049
5.3563761
30.0864436
40.2870276
-1.4491618
-16.3112736
22.9471889
0.1504459
-6.3271071
0.3431126
-12.0165391
0.8673885
12.3538070
3.9527796
26.8208050
19.3414585
-20.0851819
3.2919918
23.0616062
-3.3270374
-6.4202750
-10.9989818
-10.7957945
-6.7649738
7.3098270
12.3749523
21.2632435
-7.8273898
-4.7316528
3.5691003
0.2358017
11.5841229
-18.8802010
-8.5803274
-9.9153852
23.0644187
14.8323093
-8.5428913
-4.0749977
-11.6030498
-13.2104642
-9.3320108
-13.2439408
-6.0030504
-6.4531059
4.8319414
-0.9916749
5.1874029
2.5980703
7.5105322
-18.2285500
-4.1941249
-14.1687658
5.2498335
29.2137376
39.3085912
-1.4818560
-13.8097094
23.7003931
-3.2272844
-7.5169643
-0.5904630
-13.1924573
1.0688714
12.0190109
3.8124866
27.8865650
18.8908153
-19.8161561
4.8494418
21.0889482
-6.1251002
-6.5058596
-11.2184097
-10.8823049
-6.8383918
7.3536885
12.2578005
21.7690115
-7.4480242
-2.8945565
3.4493321
-1.1408375
10.5935031
-20.1657483
-7.4731723
-10.1376473
23.1851444
13.5945391
Download