Model

Fit the following transfer function noise model \[ co2_t =\alpha + \sum^s_{j} v_j \cdot gas_{t-j-b} + e_t, (1)\] where \(e_t\) is serially correlated.

1. Use the ideas of prewhitening taught in class to identify b and s.

According the following figure, I identify that \(b=3\) and \(s=5\) under the assumption that the gas dataset follows the AR(5) model.

acf(gas, lwd = 12, col = 'red')

pacf(gas, lwd = 12, col = 'red')

ar4model = arima(gas, order = c(5, 0, 0), include.mean = F)
newy = filter(co2, filter = c(1, -1.9203, 1.2031, -0.1670, -0.0122, -0.0566), sides = 1)
ccf(newy, ar4model$residuals, na.action = na.omit)

2. Fit Eqn. (1) based on your preliminary identification and R arima function

\[ co2_t = 53.3444 - 3.6226gas_{t+3} + 4.2126gas_{t+4} - 1.0327gas_{t+5} - 0.5856gas_{t+6} - 0.2068gas_{t+7} \]

require(dynlm)
## Loading required package: dynlm
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
glag3 = gas[3:292]
glag4 = gas[4:293]
glag5 = gas[5:294]
glag6 = gas[6:295]
glag7 = gas[7:296]
newco2 = co2[1:290]
fit = dynlm(newco2 ~ glag3 + glag4 + glag5 + glag6 + glag7)
summary(fit)
## 
## Time series regression with "zoo" data:
## Start = 1, End = 290
## 
## Call:
## dynlm(formula = newco2 ~ glag3 + glag4 + glag5 + glag6 + glag7)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -54.096 -22.085  -0.265  20.092  69.163 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 43.359661   3.842465  11.284   <2e-16 ***
## glag3        0.069683   0.041143   1.694   0.0914 .  
## glag4       -0.019418   0.058455  -0.332   0.7400    
## glag5        0.003117   0.058442   0.053   0.9575    
## glag6       -0.008293   0.057669  -0.144   0.8858    
## glag7        0.067696   0.040497   1.672   0.0957 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 27.71 on 284 degrees of freedom
## Multiple R-squared:  0.06289,    Adjusted R-squared:  0.04639 
## F-statistic: 3.812 on 5 and 284 DF,  p-value: 0.002337

3. Checking model adequacy of your fitted model.

The analysis of the model adequacy of the fitted model is as follows: According to the results from Box-Pierce test and Ljung-Box test, the p-value is very small which is smaller than 0.01, Therefore, the model I built didn’t pass the residual correlation check. With one more step further to figure out the reason, I apply the Durbin Waston Test. According to the results from the test, the p-value is also small. In conclusion, the residuals are dependent with each other.

Box.test(fit$residuals)
## 
##  Box-Pierce test
## 
## data:  fit$residuals
## X-squared = 254.62, df = 1, p-value < 2.2e-16
Box.test(fit$residuals, type = c('Ljung-Box'))
## 
##  Box-Ljung test
## 
## data:  fit$residuals
## X-squared = 257.26, df = 1, p-value < 2.2e-16
require(car)
## Loading required package: car
durbinWatsonTest(fit)
## Warning in zoo(rval[i], index(x)[i]): some methods for "zoo" objects do not
## work if the index entries in 'order.by' are not unique
##  lag Autocorrelation D-W Statistic p-value
##    1       0.9721479             0       0
##  Alternative hypothesis: rho != 0