Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Creating the time series and forecasting
- batc_haug_ts <- ts(batc_haug.mx)
- plot.ts(batc_haug_ts, ylab="Log (nr.rec)")
- batc_haug_ts_forecast_HW <- HoltWinters(batc_haug_ts, gamma=FALSE)
- batc_haug_ts_forecast_HW #alpha=0.81 and beta=0.10
- plot(batc_haug_ts_forecast_HW) #the forecast line (red) fits good with the data, however it is lagging some (a bit behind the original data)
- batc_haug_ts_forecast_HW$fitted #Level = 4.56, Trend = 0.78
- HoltWinters(batc_haug_ts, gamma=FALSE, l.start=4.56, b.start=0.78 )
- batc_haug_ts_forecast2 <- forecast(batc_haug_ts_forecast_HW
- plot(batc_haug_ts_forecast2, xlab="time", ylab="Log (nr.rec)")
- batc_haug_ts_forecast2$residuals <- na.omit(batc_haug_ts_forecast2$residuals)
- acf(batc_haug_ts_forecast2$residuals, lag.max=20)
- Box.test(batc_haug_ts_forecast2$residuals, lag=20, type="Ljung-Box") #p-value=0.1695, thus little evidence of non-zero auto correlation
- #ARIMA-model by using auto.arima
- auto.arima(batc_haug_ts) # (1,0,0) 1 paramteres
- batc_haug_ts_arima <- arima(batc_haug_ts, order = c(1, 0, 0))
- batc_haug_ts_arima #AIC=202,15
- batc_haug_ts_arima_forecast <- forecast(batc_haug_ts_arima)
- batc_haug_ts_arima_forecast
- plot(batc_haug_ts_arima_forecast)
- acf(batc_haug_ts_arima_forecast$residuals)
- pacf(batc_haug_ts_arima_forecast$residuals)
- Box.test(batc_haug_ts_arima_forecast$residuals, lag=20, type="Ljung-Box") #p-vaule=0.3001 --> little evidence of non-zero autocorrelation --> ARIMA (1,0,0) seems to be a good model
- summary(batc_haug_ts_arima_forecast) #AIC=202,15
- #By the ACF and PACF there seems to be something happening at lag 7, thus testing again with p or q =7
- batc_haug_ts_arima2 <- arima(batc_haug_ts, order = c(1, 0, 7))
- batc_haug_ts_arima2
- batc_haug_ts_arima2_forecast <- forecast(batc_haug_ts_arima2)
- batc_haug_ts_arima2_forecast
- plot(batc_haug_ts_arima2_forecast)
- acf(batc_haug_ts_arima2_forecast$residuals)
- pacf(batc_haug_ts_arima2_forecast$residuals)
- Box.test(batc_haug_ts_arima2_forecast$residuals, lag=20, type="Ljung-Box") #p-vaule=0.9835 --> little evidence of non-zero autocorrelation --> ARIMA (1,0,7) seems to be a good model
- summary(batc_haug_ts_arima2_forecast) #AIC = 204,37 thus higher than arima (1,0,0). thus the original autoarima is the best.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement