Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

STAT721 Test1 2022 Solutions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Question 1 4 marks

Given

𝑦𝑡 = 0.3 + 𝑢𝑡 + 0.5𝑢𝑡−1 − 0.3𝑢𝑡−2


𝑢𝑡 ~𝑖𝑖𝑑(0, 𝜎 2 )
a) Compute by hand 𝑐𝑜𝑟𝑟(𝑦𝑡 , 𝑦𝑡+1 ) and 𝑐𝑜𝑟𝑟(𝑦𝑡 , 𝑦𝑡+2 )

𝐶𝑜𝑣(𝑦𝑡 , 𝑦𝑡 ) = 𝐶𝑜𝑣(𝑢𝑡 + 0.5𝑢𝑡−1 − 0.3𝑢𝑡−2 ; 𝑢𝑡 + 0.5𝑢𝑡−1 − 0.3𝑢𝑡−2 )


= 𝐶𝑜𝑣(𝑢𝑡 ; 𝑢𝑡 ) + 0.5𝑐𝑜𝑣 (𝑢𝑡 ; 𝑢𝑡−1 ) − 0.3𝐶𝑜𝑣(𝑢𝑡 ; 𝑢𝑡−2 )

+0.5𝑐𝑜𝑣 (𝑢𝑡−1 ; 𝑢𝑡 ) + 0.52 𝐶𝑜𝑣(𝑢𝑡−1 ; 𝑢𝑡−1 ) − 0.5(0.3)𝑐𝑜𝑣 (𝑢𝑡−1 ; 𝑢𝑡−2 )

−0.3𝐶𝑜𝑣(𝑢𝑡−2 ; 𝑢𝑡 ) − 0.3(0.5)𝑐𝑜𝑣 (𝑢𝑡−2 ; 𝑢𝑡−1 )+(−0.3)2 𝐶𝑜𝑣(𝑢𝑡−2 ; 𝑢𝑡−2 )


= (1 + 0.52 + (−0.32 ))𝜎 2 = 1.34𝜎 2

𝐶𝑜𝑣(𝑦𝑡 , 𝑦𝑡+1 ) = 𝐶𝑜𝑣(𝑢𝑡 + 0.5𝑢𝑡−1 − 0.3𝑢𝑡−2 ; 𝑢𝑡+1 + 0.5𝑢𝑡 − 0.3𝑢𝑡−1 )


= 𝐶𝑜𝑣(𝑢𝑡 ; 𝑢𝑡+1 ) + 0.5𝑐𝑜𝑣 (𝑢𝑡 ; 𝑢𝑡 ) − 0.3𝐶𝑜𝑣(𝑢𝑡 ; 𝑢𝑡−1 )

+0.5𝑐𝑜𝑣 (𝑢𝑡−1 ; 𝑢𝑡+1 ) + 0.52 𝐶𝑜𝑣(𝑢𝑡−1 ; 𝑢𝑡 ) − 0.5(0.3)𝑐𝑜𝑣 (𝑢𝑡−1 ; 𝑢𝑡−1 )

−0.3𝐶𝑜𝑣(𝑢𝑡−2 ; 𝑢𝑡+1 ) − 0.3(0.5)𝑐𝑜𝑣 (𝑢𝑡−2 ; 𝑢𝑡 )+(−0.3)2 𝐶𝑜𝑣(𝑢𝑡−2 ; 𝑢𝑡−1 )


=[0.5 − 0.3(0.5)] 𝜎 2 = 0.35𝜎 2

𝐶𝑜𝑣(𝑦𝑡 , 𝑦𝑡+2 ) = 𝐶𝑜𝑣(𝑢𝑡 + 0.5𝑢𝑡−1 − 0.3𝑢𝑡−2 ; 𝑢𝑡+2 + 0.5𝑢𝑡+1 − 0.3𝑢𝑡 )


= 𝐶𝑜𝑣(𝑢𝑡 ; 𝑢𝑡+2 ) + 0.5𝑐𝑜𝑣 (𝑢𝑡 ; 𝑢𝑡+1 ) − 0.3𝐶𝑜𝑣(𝑢𝑡 ; 𝑢𝑡 )
+0.5𝑐𝑜𝑣 (𝑢𝑡−1 ; 𝑢𝑡+2 ) + 0.52 𝐶𝑜𝑣(𝑢𝑡−1 ; 𝑢𝑡+1 ) − 0.5(0.3)𝑐𝑜𝑣 (𝑢𝑡−1 ; 𝑢𝑡 )

−0.3𝐶𝑜𝑣(𝑢𝑡−2 ; 𝑢𝑡+2 ) − 0.3(0.5)𝑐𝑜𝑣 (𝑢𝑡−2 ; 𝑢𝑡+1 )+(−0.3)2 𝐶𝑜𝑣(𝑢𝑡−2 ; 𝑢𝑡 )

=−0.3𝜎 2

=> 𝑐𝑜𝑟𝑟(𝑦𝑡 , 𝑦𝑡+1 ) =0.35/1.34=0.2612

𝑐𝑜𝑟𝑟(𝑦𝑡 , 𝑦𝑡+2 ) =-0.3/1.34=-0.2238


b) Now use appropriate R code to compute a partial autocorrelation function for the first 4 lags
> ARMAacf(ma=c(0.5,-0.3),pacf=TRUE,lag.max=4)
[1] 0.2611940 -0.3134899 0.1888699 -0.1654122

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

> ts.plot(airmiles, xlab="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

Residual standard error: 0.1398 on 112 degrees of freedom

ln 𝑦𝑡 = 17.50735 + 𝑢𝑡 ; 𝑢𝑡 ~𝑖𝑖𝑑(0, 𝜎 2 = 0.13982 )

c) Generate an autocorrelation plot for ln 𝑦𝑡

> out=acf(airmiles, type="correlation")


d) Given that there is autocorrelation in the data, what consequence does this have for the
standard error associated with the estimate of µ that you obtained in (b)
The standard errors will be incorrect/inconsistent

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))

Lag truncation parameter chosen: 2

t test of coefficients:

Estimate Std. Error t value Pr(>|t|)


(Intercept) 17.507347 0.024388 717.86 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

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 )

compute appropriate expressions for

𝑦̂𝑡+𝑘|𝑡 ≡ 𝐸(𝑦𝑡+𝑘 |𝑦𝑡 … 𝑦1 )

and

𝑉𝑎𝑟(𝑒̂𝑡+𝑘|𝑡 |𝑦𝑡 … 𝑦1 )

where 𝑒̂𝑡+𝑘|𝑡 ≡ 𝑦𝑡+𝑘 − 𝐸(𝑦𝑡+𝑘 |𝑦𝑡 … 𝑦1 )

Note

𝑦𝑡+𝑘 = 𝑦𝑡 + 2𝑘 + 𝑢𝑡+𝑘 + ⋯ + 𝑢𝑡+1


 𝐸(𝑦𝑡+𝑘 |𝑦𝑡 … 𝑦1 ) = 2𝑘
 𝑉𝑎𝑟(𝑒̂𝑡+𝑘|𝑡 |𝑦𝑡 … 𝑦1 ) = 𝑉𝑎𝑟(𝑢𝑡+𝑘 + ⋯ + 𝑢𝑡+1 ) = 𝑘𝜎 2
Question 4 10 marks

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

sigma^2 = 6.139: log likelihood = -307.02


AIC=622.05 AICc=622.36 BIC=633.58

𝑦𝑡 = 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

sigma^2 = 12.04: log likelihood = -348.34


AIC=700.68 AICc=700.77 BIC=706.43

𝑦𝑡 = 𝑦𝑡−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

data: Residuals from ARIMA(0,1,0) with drift


Q* = 573.99, df = 23, p-value < 2.2e-16

Model df: 1. Total lags used: 24

Conclude model fit NOT adequate


f) How could you set about improving the model fits that you have obtained in the
question
Need to include an annual seasonal component

You might also like