Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #Creating the time series and forecasting
  2. batc_haug_ts <- ts(batc_haug.mx)
  3. plot.ts(batc_haug_ts, ylab="Log (nr.rec)")
  4. batc_haug_ts_forecast_HW <- HoltWinters(batc_haug_ts, gamma=FALSE)
  5.  
  6. batc_haug_ts_forecast_HW #alpha=0.81 and beta=0.10
  7. 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)
  8.  
  9. batc_haug_ts_forecast_HW$fitted #Level = 4.56, Trend = 0.78
  10. HoltWinters(batc_haug_ts, gamma=FALSE, l.start=4.56, b.start=0.78 )
  11. batc_haug_ts_forecast2 <- forecast(batc_haug_ts_forecast_HW
  12. plot(batc_haug_ts_forecast2, xlab="time", ylab="Log (nr.rec)")
  13.  
  14.  
  15. batc_haug_ts_forecast2$residuals <- na.omit(batc_haug_ts_forecast2$residuals)
  16.  
  17. acf(batc_haug_ts_forecast2$residuals, lag.max=20)
  18. Box.test(batc_haug_ts_forecast2$residuals, lag=20, type="Ljung-Box") #p-value=0.1695, thus little evidence of non-zero auto correlation
  19.  
  20. #ARIMA-model by using auto.arima
  21. auto.arima(batc_haug_ts) # (1,0,0) 1 paramteres
  22. batc_haug_ts_arima <- arima(batc_haug_ts, order = c(1, 0, 0))
  23. batc_haug_ts_arima #AIC=202,15
  24. batc_haug_ts_arima_forecast <- forecast(batc_haug_ts_arima)
  25. batc_haug_ts_arima_forecast
  26. plot(batc_haug_ts_arima_forecast)
  27. acf(batc_haug_ts_arima_forecast$residuals)
  28. pacf(batc_haug_ts_arima_forecast$residuals)
  29. 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
  30.  
  31. summary(batc_haug_ts_arima_forecast) #AIC=202,15
  32.  
  33. #By the ACF and PACF there seems to be something happening at lag 7, thus testing again with p or q =7
  34.  
  35. batc_haug_ts_arima2 <- arima(batc_haug_ts, order = c(1, 0, 7))
  36. batc_haug_ts_arima2
  37. batc_haug_ts_arima2_forecast <- forecast(batc_haug_ts_arima2)
  38. batc_haug_ts_arima2_forecast
  39. plot(batc_haug_ts_arima2_forecast)
  40. acf(batc_haug_ts_arima2_forecast$residuals)
  41. pacf(batc_haug_ts_arima2_forecast$residuals)
  42. 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
  43.  
  44. 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