You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# An assumption for linear modeling is that the residuals are not correlated
72
+
# However, often in time series data that is not true thus we need to check for correlation in the residuals
73
+
e.ts.bike<- ts(bike.trendseason$residuals)
93
74
94
-
# Plot acf and pacf side by side for easier examination
75
+
# Plot autocorrelation (acf) and partial autocorrelation (pacf)
76
+
# ACF and PACF measure the correlation of residuals and give incite into which models to use (see diagram)
95
77
par(mfrow=c(1,2))
96
-
acf(e.ts.bike2, main="ACF of Residuals from bike.season")
97
-
pacf(e.ts.bike2,main="PACF of Residuals from bike.season")
78
+
acf(e.ts.bike, main="ACF of Residuals from e.ts.bike")
79
+
pacf(e.ts.bike,main="PACF of Residuals from e.ts.bike")
98
80
par(mfrow=c(1,1))
99
81
100
-
# Sinusodial decay on ACF and not on PACF - AR or ARMA
101
-
bike.arma13<- arima(e.ts.bike2, order=c(1,0,3))
82
+
# ACF is sidusodial decay
83
+
# PACF cannot see any trends
84
+
# Choose AR or ARMA
85
+
86
+
# Autoregressive: AR(p) models: "The AR model establishes that a realization at time t is a linear combination of the p previous realization plus some noise term."
87
+
# Moving Average: MA(q): "can define correlated noise structure in our data and goes beyond the traditional assumption where errors are iid."
88
+
# ARMA: combines autoregressive and moving average terms
89
+
# ARIMA: combines autoregressive and moving average terms when the data in non-stationary - i.e. mean, variance, autocorrelation, etc. are not constant overtime
90
+
91
+
# Choose p values for AR model
92
+
# ar(3) p=3
93
+
bike.ar3<- arima(e.ts.bike, order=c(3,0,0))
94
+
summary(bike.ar3)
95
+
96
+
# Choose p and r values for ARMA model
97
+
bike.arma13<- arima(e.ts.bike, order= c(1,0,3))
98
+
summary(bike.arma13)
102
99
103
100
# Use the auto.arima from 'forecast' library- Automatically find p, q, & d terms
104
-
bike2.auto<- auto.arima(e.ts.bike2, trace=TRUE)
105
-
# Best model is ARIMA(2,1,1)
101
+
library('forecast')
102
+
bike.auto<- auto.arima(e.ts.bike, trace=TRUE)
103
+
# Using autoregressive function the best model is ARIMA(2,1,1)
0 commit comments