temp<-read.table("temp.txt", header=T)
temp.ts<-ts(temp$temps, frequency=12) #create monthly time series
plot(temp.ts)
library(TTR)
## Warning: package 'TTR' was built under R version 4.3.2
temp.ma<-SMA(temp.ts, n = 5)
lines(temp.ma, col="red", lwd=2)

temp.decomp<-decompose(temp.ts)
plot(temp.decomp)

acf(temp.ts)

acf(temp.decomp$random[!is.na(temp.decomp$random)])

pacf(temp.ts)

library(forecast)
## Warning: package 'forecast' was built under R version 4.3.2
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
temp.fit<-auto.arima(temp.ts)
summary(temp.fit)
## Series: temp.ts
## ARIMA(0,0,1)(2,1,0)[12]
##
## Coefficients:
## ma1 sar1 sar2
## 0.2456 -0.5212 -0.3233
## s.e. 0.0774 0.0823 0.0827
##
## sigma^2 = 3.772: log likelihood = -300.76
## AIC=609.52 AICc=609.81 BIC=621.4
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.2384692 1.846384 1.498262 0.2682136 11.90101 0.8327783
## ACF1
## Training set 0.005413047
checkresiduals(temp.fit)

##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,0,1)(2,1,0)[12]
## Q* = 38.688, df = 21, p-value = 0.01069
##
## Model df: 3. Total lags used: 24
temp.fcast<-forecast(temp.fit)
plot(temp.fcast)
