1.

#annual data
Annual <- scan("http://www.calpoly.edu/~gbdurham/econ522/precip/annual_precip.csv")
Annual <- ts(Annual)

#monthly data
monthly <- scan("http://www.calpoly.edu/~gbdurham/econ522/precip/monthly_precip.csv")
monthly <- ts(monthly, frequency = 12, start = c(0,6))

2.

plot.ts(Annual)

3.

plot.ts(Annual)
s = ksmooth(1:145,Annual,bandwidth = 5)
lines(smooth(s$y),col = 3)

4.

res = Annual - s$y
par(mfrow=c(2,1))
plot(res)
hist(res)

par(mfrow=c(1,1))
acf(res)

#The residuals seem normal

4.

lamda <- 0.5
z = ((Annual^lamda)-1)/lamda
zSmooth<- ksmooth(1:145,z,bandwidth = 5)
Z_Res <- z - zSmooth$y
plot(Z_Res)

hist(Z_Res)

#Residuals at Lamda = 0.5 seem to be normal

5.

Monthly <- ts(monthly, frequency = 12, start = c(0,6))
monthplot(Monthly)

MonthSmooth<- ksmooth(1:1740,Monthly,bandwidth = 5)
Monthly_Res <- Monthly - MonthSmooth$y
plot(Monthly_Res)

hist(Monthly_Res)

#does not seem to appear normal before transformation


lamda <- 0.5
z = ((Monthly^lamda)-1)/lamda
zSmooth<- ksmooth(1:1740,Monthly,bandwidth = 5)
Z_Res <- z - zSmooth$y
plot(Z_Res)

hist(Z_Res)

#Seems to be normal after Box Cox Transformation

6.

Monthlyfactor <- factor(cycle(z))
Dummy1<- model.matrix(z~ Monthlyfactor)
Dummy1<- Dummy1[,-1]

auto.arima(z, xreg = Dummy1)
## Series: z 
## ARIMA(1,0,0)(2,0,2)[12] with non-zero mean 
## 
## Coefficients:
## Warning in sqrt(diag(x$var.coef)): NaNs produced
##          ar1     sar1    sar2    sma1     sma2  intercept  Monthlyfactor2
##       0.0879  -0.2526  0.4896  0.2630  -0.4521     1.7626         -0.3676
## s.e.  0.0141      NaN     NaN  0.0087   0.0154     0.1144          0.1546
##       Monthlyfactor3  Monthlyfactor4  Monthlyfactor5  Monthlyfactor6
##              -1.6098         -2.8217         -3.4596         -3.6535
## s.e.          0.1612          0.1618          0.1618          0.1618
##       Monthlyfactor7  Monthlyfactor8  Monthlyfactor9  Monthlyfactor10
##              -3.6335         -3.2443         -2.3462          -1.3704
## s.e.          0.1618          0.1618          0.1618           0.1618
##       Monthlyfactor11  Monthlyfactor12
##               -0.1761           0.1197
## s.e.           0.1612           0.1546
## 
## sigma^2 estimated as 1.671:  log likelihood=-2915.77
## AIC=5867.54   AICc=5867.93   BIC=5965.84
ARTrend<- arima(z, order = c(1,0,0), include.mean = FALSE, xreg = Dummy1)
ARTrend2<- arima(z, order = c(2,0,1), include.mean = FALSE, xreg = Dummy1)
## Warning in arima(z, order = c(2, 0, 1), include.mean = FALSE, xreg =
## Dummy1): possible convergence problem: optim gave code = 1
#AIC on ARMA (2,1) had the Lowest AIC of 5881.75
require(graphics)
tsdiag(ARTrend)

tsdiag(ARTrend2)

SARTrend<- sarima(z,1,0,0,2,0,2,12, tol = .00001)
## initial  value 0.659149 
## iter   2 value 0.456323
## iter   3 value 0.405773
## iter   4 value 0.393314
## iter   5 value 0.372410
## iter   6 value 0.365299
## iter   7 value 0.340690
## iter   8 value 0.324793
## iter   9 value 0.316972
## iter  10 value 0.308767
## iter  11 value 0.300280
## iter  12 value 0.294186
## iter  13 value 0.293110
## iter  14 value 0.291942
## iter  15 value 0.291885
## iter  16 value 0.291854
## iter  17 value 0.291799
## iter  18 value 0.291720
## iter  19 value 0.291544
## iter  20 value 0.291443
## iter  21 value 0.291362
## iter  22 value 0.291352
## iter  23 value 0.291348
## iter  23 value 0.291348
## iter  23 value 0.291348
## final  value 0.291348 
## converged
## initial  value 0.289216 
## iter   2 value 0.288303
## iter   3 value 0.288117
## iter   4 value 0.287693
## iter   5 value 0.287301
## iter   6 value 0.287027
## iter   7 value 0.286204
## iter   8 value 0.285661
## iter   9 value 0.285037
## iter  10 value 0.284847
## iter  11 value 0.284759
## iter  12 value 0.284710
## iter  13 value 0.284625
## iter  13 value 0.284640
## iter  14 value 0.284567
## iter  15 value 0.284507
## iter  16 value 0.284441
## iter  17 value 0.284052
## iter  18 value 0.283660
## iter  19 value 0.283076
## iter  20 value 0.282198
## iter  21 value 0.280524
## iter  22 value 0.280410
## iter  23 value 0.280284
## iter  24 value 0.280225
## iter  25 value 0.279961
## iter  26 value 0.279924
## iter  26 value 0.280343
## final  value 0.279924 
## converged

SARTrend2<- sarima(z,2,0,1,2,0,0,12, tol = .00001)
## initial  value 0.659165 
## iter   2 value 0.468578
## iter   3 value 0.410652
## iter   4 value 0.390392
## iter   5 value 0.389414
## iter   6 value 0.389269
## iter   6 value 0.389267
## iter   6 value 0.389267
## final  value 0.389267 
## converged
## initial  value 0.390395 
## iter   2 value 0.390391
## iter   3 value 0.390363
## iter   3 value 0.390362
## iter   3 value 0.390362
## final  value 0.390362 
## converged

#AIC and AICc of Seasonal arima with (1,0,0)(2,0,2) is smaller than the other test seasonal Arimas.