---
title: "Homework 2.1"
author: "Garland Durham"
date: "January 23, 2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(astsa)
```


```{r fig.height=8}
plot(jj)
plot(log(jj))
logjj = log(jj)
Q = factor( cycle( jj ))
trend = time(jj) - 1970
fit01 = lm( logjj ~ 0 + trend + Q )
summary(fit01)
ts.plot( cbind(logjj, fitted(fit01)), col=1:2, type="o", main="JJ, quarterly earnings per share", ylab="Dollars")
plot.ts(residuals(fit01), type="o", main="JJ earnings, residuals", ylab="Dollars")
acf(residuals(fit01), main="ACF, JJ residuals")
pacf(residuals(fit01), main="PACF, JJ residuals")
```

The residuals do not look like white noise.  There is too much autocorrelation.  

Let's try seasonal ARIMA, with differenced data at the annual frequency.

```{r fig.height=8}
fit02 = sarima( logjj, 0,0,0, 0,1,0, 4, details=FALSE )
AIC( fit01, fit02$fit )
BIC( fit01, fit02$fit )
plot( residuals( fit02$fit ))
acf( residuals( fit02$fit ))
pacf( residuals( fit02$fit ))
```

Definitely still some autocorrelation in the residuals...

Let's try a few more models...

```{r fig.height=8}
fit04 = sarima( logjj, 1,0,0, 0,1,0, 4, details=FALSE )
fit05 = sarima( logjj, 0,0,1, 0,1,0, 4, details=FALSE )
fit06 = sarima( logjj, 1,0,1, 0,1,0, 4, details=FALSE )

fit07 = sarima( logjj, 2,0,0, 0,1,0, 4, details=FALSE )
fit08 = sarima( logjj, 2,0,1, 0,1,0, 4, details=FALSE )
fit09 = sarima( logjj, 1,0,2, 0,1,0, 4, details=FALSE )

AIC( fit01, fit02$fit, fit04$fit, fit05$fit, fit06$fit, fit07$fit, fit08$fit, fit09$fit )
BIC( fit01, fit02$fit, fit04$fit, fit05$fit, fit06$fit, fit07$fit, fit08$fit, fit09$fit )

fit04
fit07
fit09

```

BIC prefers $\text{ARIMA}(1,0,0)\times(0,1,0)_{12}$.  AIC prefers a couple of larger models, but notice that the
additional parameters are not significant at the 0.05 level.  I would tend to go with the BIC.  The diagnostics look good.



```



