We will now see how we can fit an AR model to a given time series using the arima() function in R. Recall that AR model is an ARIMA(1, 0, 0) model.
We can use the arima() function in R to fit the AR model by specifying the order = c(1, 0, 0).
We will perform the estimation using the msft_ts time series that we created earlier in the first lesson. If you don't have the msft_ts loaded in your R session, please follow the steps to create it as specified in the first lesson.
Let's start by creating a plot of the original data using the plot.ts() function.
As of now we are not worried about whether an AR model is best suited for this data or not. Our objective is to understand the process of fitting the AR model to this data.
We will fit the AR model to this data using the following command:
msft_ar <- arima(msft_ts , order = c(1, 0, 0))
The output contains many things including the estimated slope (ar1), mean (intercept), and innovation variance (sigma^2) as shown below: