Zeitreihenanalyse - Übung 10

From StatWiki
Jump to: navigation, search

Exercise

Fit an AR model of order 1 to the growth rates of the quarterly GDP and plot its spectral density.

Exercise

Fit an ARMA(1,2) model to the growth rates of the quarterly GDP

> GDPC1 <- readdataSK("GDPC1.txt","table")
>
> GDP <- ts(data=GDPC1[,2])
> d <- diff(log(GDP),k=-1); n <- length(d)
> m <- floor(n/2)
>
> d.dm <- d-mean(d) # d is demeaned
>
> ms = c(outer(0:4, 0:4, function(p,q) { apply(cbind(p,q), 1, function(row) {
+   p = row[1]; q = row[2]
+   arima(d.dm,order=c(p,0,q),include.mean=FALSE,transform.pars=TRUE)
+ })  }))
Warning messages:
1: In arima(d.dm, order = c(p, 0, q), include.mean = FALSE, transform.pars = TRUE) :
  possible convergence problem: optim gave code = 1
2: In arima(d.dm, order = c(p, 0, q), include.mean = FALSE, transform.pars = TRUE) :
  possible convergence problem: optim gave code = 1
>
> ms[sort(sapply(ms, function(x) x$aic),index.return=TRUE)$ix[1:3]]
[[1]]

Call:
arima(x = d.dm, order = c(p, 0, q), include.mean = FALSE, transform.pars = TRUE)

Coefficients:
         ar1      ar2     ar3      ma1    ma2
      1.6593  -1.2884  0.2198  -1.4039  1.000
s.e.  0.0635   0.0931  0.0629   0.0158  0.018

sigma^2 estimated as 7.708e-05:  log likelihood = 813.21,  aic = -1614.43

[[2]]

Call:
arima(x = d.dm, order = c(p, 0, q), include.mean = FALSE, transform.pars = TRUE)

Coefficients:
         ar1      ar2     ar3      ma1     ma2      ma3
      1.7645  -1.4404  0.3213  -1.5128  1.1518  -0.1081
s.e.  0.1984   0.2874  0.1920   0.2027  0.2831   0.2008

sigma^2 estimated as 7.701e-05:  log likelihood = 813.35,  aic = -1612.71

[[3]]

Call:
arima(x = d.dm, order = c(p, 0, q), include.mean = FALSE, transform.pars = TRUE)

Coefficients:
         ar1      ar2     ar3     ar4      ma1     ma2
      1.7117  -1.2048  0.0595  0.0967  -1.4504  0.9497
s.e.  0.0726   0.1346  0.1298  0.0664   0.0385  0.0389

sigma^2 estimated as 7.828e-05:  log likelihood = 813.09,  aic = -1612.18

Data for validation

V1      V2
1   1947-01-01  1570.5
2   1947-04-01  1568.7
3   1947-07-01  1568.0
4   1947-10-01  1590.9
5   1948-01-01  1616.1
6   1948-04-01  1644.6
7   1948-07-01  1654.1
8   1948-10-01  1658.0
9   1949-01-01  1633.2
10  1949-04-01  1628.4
11  1949-07-01  1646.7
12  1949-10-01  1629.9
13  1950-01-01  1696.8
14  1950-04-01  1747.3
15  1950-07-01  1815.8
16  1950-10-01  1848.9
17  1951-01-01  1871.3
18  1951-04-01  1903.1
19  1951-07-01  1941.1
20  1951-10-01  1944.4
21  1952-01-01  1964.7
22  1952-04-01  1966.0
23  1952-07-01  1978.8
24  1952-10-01  2043.8
25  1953-01-01  2082.3
26  1953-04-01  2098.1
27  1953-07-01  2085.4
28  1953-10-01  2052.5
29  1954-01-01  2042.4
30  1954-04-01  2044.3
31  1954-07-01  2066.9
32  1954-10-01  2107.8
33  1955-01-01  2168.5
34  1955-04-01  2204.0
35  1955-07-01  2233.4
36  1955-10-01  2245.3
37  1956-01-01  2234.8
38  1956-04-01  2252.5
39  1956-07-01  2249.8
40  1956-10-01  2286.5
41  1957-01-01  2300.3
42  1957-04-01  2294.6
43  1957-07-01  2317.0
44  1957-10-01  2292.5
45  1958-01-01  2230.2
46  1958-04-01  2243.4
47  1958-07-01  2295.2
48  1958-10-01  2348.0
49  1959-01-01  2392.9
50  1959-04-01  2455.8
51  1959-07-01  2453.9
52  1959-10-01  2462.6
53  1960-01-01  2517.4
54  1960-04-01  2504.8
55  1960-07-01  2508.7
56  1960-10-01  2476.2
57  1961-01-01  2491.2
58  1961-04-01  2538.0
59  1961-07-01  2579.1
60  1961-10-01  2631.8
61  1962-01-01  2679.1
62  1962-04-01  2708.4
63  1962-07-01  2733.3
64  1962-10-01  2740.0
65  1963-01-01  2775.9
66  1963-04-01  2810.6
67  1963-07-01  2863.5
68  1963-10-01  2885.8
69  1964-01-01  2950.5
70  1964-04-01  2984.8
71  1964-07-01  3025.5
72  1964-10-01  3033.6
73  1965-01-01  3108.2
74  1965-04-01  3150.2
75  1965-07-01  3214.1
76  1965-10-01  3291.8
77  1966-01-01  3372.3
78  1966-04-01  3384.0
79  1966-07-01  3406.3
80  1966-10-01  3433.7
81  1967-01-01  3464.1
82  1967-04-01  3464.3
83  1967-07-01  3491.8
84  1967-10-01  3518.2
85  1968-01-01  3590.7
86  1968-04-01  3651.6
87  1968-07-01  3676.5
88  1968-10-01  3692.0
89  1969-01-01  3750.2
90  1969-04-01  3760.9
91  1969-07-01  3784.2
92  1969-10-01  3766.3
93  1970-01-01  3760.0
94  1970-04-01  3767.1
95  1970-07-01  3800.5
96  1970-10-01  3759.8
97  1971-01-01  3864.1
98  1971-04-01  3885.9
99  1971-07-01  3916.7
100 1971-10-01  3927.9
101 1972-01-01  3997.7
102 1972-04-01  4092.1
103 1972-07-01  4131.1
104 1972-10-01  4198.7
105 1973-01-01  4305.3
106 1973-04-01  4355.1
107 1973-07-01  4331.9
108 1973-10-01  4373.3
109 1974-01-01  4335.4
110 1974-04-01  4347.9
111 1974-07-01  4305.8
112 1974-10-01  4288.9
113 1975-01-01  4237.6
114 1975-04-01  4268.6
115 1975-07-01  4340.9
116 1975-10-01  4397.8
117 1976-01-01  4496.8
118 1976-04-01  4530.3
119 1976-07-01  4552.0
120 1976-10-01  4584.6
121 1977-01-01  4640.0
122 1977-04-01  4731.1
123 1977-07-01  4815.8
124 1977-10-01  4815.3
125 1978-01-01  4830.8
126 1978-04-01  5021.2
127 1978-07-01  5070.7
128 1978-10-01  5137.4
129 1979-01-01  5147.4
130 1979-04-01  5152.3
131 1979-07-01  5189.4
132 1979-10-01  5204.7
133 1980-01-01  5221.3
134 1980-04-01  5115.9
135 1980-07-01  5107.4
136 1980-10-01  5202.1
137 1981-01-01  5307.5
138 1981-04-01  5266.1
139 1981-07-01  5329.8
140 1981-10-01  5263.4
141 1982-01-01  5177.1
142 1982-04-01  5204.9
143 1982-07-01  5185.2
144 1982-10-01  5189.8
145 1983-01-01  5253.8
146 1983-04-01  5372.3
147 1983-07-01  5478.4
148 1983-10-01  5590.5
149 1984-01-01  5699.8
150 1984-04-01  5797.9
151 1984-07-01  5854.3
152 1984-10-01  5902.4
153 1985-01-01  5956.9
154 1985-04-01  6007.8
155 1985-07-01  6101.7
156 1985-10-01  6148.6
157 1986-01-01  6207.4
158 1986-04-01  6232.0
159 1986-07-01  6291.7
160 1986-10-01  6323.4
161 1987-01-01  6365.0
162 1987-04-01  6435.0
163 1987-07-01  6493.4
164 1987-10-01  6606.8
165 1988-01-01  6639.1
166 1988-04-01  6723.5
167 1988-07-01  6759.4
168 1988-10-01  6848.6
169 1989-01-01  6918.1
170 1989-04-01  6963.5
171 1989-07-01  7013.1
172 1989-10-01  7030.9
173 1990-01-01  7112.1
174 1990-04-01  7130.3
175 1990-07-01  7130.8
176 1990-10-01  7076.9
177 1991-01-01  7040.8
178 1991-04-01  7086.5
179 1991-07-01  7120.7
180 1991-10-01  7154.1
181 1992-01-01  7228.2
182 1992-04-01  7297.9
183 1992-07-01  7369.5
184 1992-10-01  7450.7
185 1993-01-01  7459.7
186 1993-04-01  7497.5
187 1993-07-01  7536.0
188 1993-10-01  7637.4
189 1994-01-01  7715.1
190 1994-04-01  7815.7
191 1994-07-01  7859.5
192 1994-10-01  7951.6
193 1995-01-01  7973.7
194 1995-04-01  7988.0
195 1995-07-01  8053.1
196 1995-10-01  8112.0
197 1996-01-01  8169.2
198 1996-04-01  8303.1
199 1996-07-01  8372.7
200 1996-10-01  8470.6
201 1997-01-01  8536.1
202 1997-04-01  8665.8
203 1997-07-01  8773.7
204 1997-10-01  8838.4
205 1998-01-01  8936.2
206 1998-04-01  8995.3
207 1998-07-01  9098.9
208 1998-10-01  9237.1
209 1999-01-01  9315.5
210 1999-04-01  9392.6
211 1999-07-01  9502.2
212 1999-10-01  9671.1
213 2000-01-01  9695.6
214 2000-04-01  9847.9
215 2000-07-01  9836.6
216 2000-10-01  9887.7
217 2001-01-01  9875.6
218 2001-04-01  9905.9
219 2001-07-01  9871.1
220 2001-10-01  9910.0
221 2002-01-01  9977.3
222 2002-04-01 10031.6
223 2002-07-01 10090.7
224 2002-10-01 10095.8
225 2003-01-01 10126.0
226 2003-04-01 10212.7
227 2003-07-01 10398.7
228 2003-10-01 10467.0
229 2004-01-01 10543.6
230 2004-04-01 10634.2
231 2004-07-01 10728.7
232 2004-10-01 10796.4
233 2005-01-01 10875.8
234 2005-04-01 10946.1
235 2005-07-01 11050.0
236 2005-10-01 11086.1
237 2006-01-01 11217.3
238 2006-04-01 11291.7
239 2006-07-01 11314.1
240 2006-10-01 11356.4
241 2007-01-01 11357.8
242 2007-04-01 11491.4
243 2007-07-01 11625.7
244 2007-10-01 11620.7
245 2008-01-01 11646.0
246 2008-04-01 11727.4
247 2008-07-01 11712.3