STAT721 Test1 2022 Solutions
STAT721 Test1 2022 Solutions
STAT721 Test1 2022 Solutions
Given
=−0.3𝜎 2
Question 2 8 marks
Use the following code to load a dataset called airmiles into RStudio from the TSA package
> library(TSA)
> data(airmiles)
> class(airmiles)
[1] "ts"
> frequency(airmiles)
[1] 12
a) Generate a plot of the data making sure that the label on the time axis reads
Time in months
b) Use appropriate code to fit the following model to this data set
ln 𝑦𝑡 = µ + 𝑢𝑡 ; 𝑢𝑡 ~𝑖𝑖𝑑(0, 𝜎 2 )
Clearly list the output that you have obtained along with the appropriate coding that has been
used.
> airmiles=log(airmiles)
> out=lm(airmiles~1)
> summary(out)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 17.50735 0.01315 1332 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
e) Use appropriate code to perform a Newey-West adjustment to the results you obtained
in (i). Clearly show the code that you have used and the results you have obtained
> coeftest(out,vcov=NeweyWest(out,verbose=T))
t test of coefficients:
f) Assume we want to test 𝐻0 : 𝜇 = 17. Use the output in e) to derive an appropriate t-value
for testing this hypothesis.
17.507−17
𝑡= 0.02438
=20.79
Question 3 3 marks
Given
𝑦𝑡 = 𝑦𝑡−1 + 2 + 𝑢𝑡 ; 𝑢𝑡 ~𝑖𝑖𝑑(0, 𝜎 2 )
and
𝑉𝑎𝑟(𝑒̂𝑡+𝑘|𝑡 |𝑦𝑡 … 𝑦1 )
Note
Use the following code to load a dataset called co2 into RStudio from the TSA package
> library(TSA)
> library(forecast)
> data(co2)
> head(co2)
Jan Feb Mar Apr May Jun
1994 363.05 364.18 364.87 364.47 364.32 362.13
> plot(co2)
a) Clearly list appropriate code that will fit a AR(2) model with a nonzero mean to this data
set. Write down the model structure that has been estimated
> library(forecast)
> fit= Arima(co2,order=c(2,0,0))
> fit
Series: co2
ARIMA(2,0,0) with non-zero mean
Coefficients:
ar1 ar2 mean
1.5193 -0.6874 369.1537
s.e. 0.0625 0.0627 1.2611
𝑦𝑡 = 369.153 + 𝑒𝑡
𝑒𝑡 = 1.5193𝑒𝑡−1 − 0.6874𝑒𝑡−1 + 𝑢𝑡
b)Fit a model with an appropriate linear trend to this data. Clearly list the code you have
used and write down the model structure that has been estimated
> t=time(co2)
> head(t)
Jan Feb Mar Apr May Jun
1959 1959.000 1959.083 1959.167 1959.250 1959.333 1959.417
> out=lm(co2~t)
> out
Coefficients:
(Intercept) t
-3127.241 1.749
𝑦𝑡 = −3127.24 + 1.749 ∗ 𝑡 + 𝑒𝑡
c) Use the above fitted model to forecast and outcome for co2 for April 1998
forecast=-3127.24+1.749*1998.25=367.69
d)Now fit a random walk model with a non-zero drift term to this dataset. Clearly list the
code you have used and write down the model structure that has been estimated
> out=Arima(co2,c(0,1,0),include.drift=TRUE)
> out
Series: co2
ARIMA(0,1,0) with drift
Coefficients:
drift
0.1418
s.e. 0.3020
𝑦𝑡 = 𝑦𝑡−1 + 0.1418 + 𝑒𝑡
e)Perform an appropriate test to determine if the model that has been fitted in d) is adequate
> checkresiduals(out)
Ljung-Box test