13.4 Autoregressive models

A variation of the random walk model described previously is the autoregressive time series model of order 1, AR(1). This model is essentially the same as the random walk model but it introduces an estimated coefficient, which we will call \(\phi\). The parameter \(\phi\) controls the degree to which the random walk reverts to the mean – when \(\phi\) = 1, the model is identical to the random walk, but at smaller values, the model will revert back to the mean (which in this case is zero). Also, \(\phi\) can take on negative values, which we’ll discuss more in future lectures. The math to describe the AR(1) model is: \[y_t = \phi y_{t-1} + e_{t}\].

The fit_stan() function can fit higher order AR models, but for now we just want to fit an AR(1) model and make a histogram of phi.

ar1 <- atsar::fit_stan(y = Temp, x = matrix(1, nrow = length(Temp), 
    ncol = 1), model_name = "ar", est_drift = FALSE, P = 1)