Solved – Fitting model AR(1) with R

arimaautoregressivertime series

I've sampled 100 variables from a Gauss distribution with mean 0 and standard deviation 1.

> set.seed(1)
> wn=rnorm(100)

Then I've fitted an AR(1) model with the arima command and sent the results to the wnF variable

> wnF=arima(wn, order=c(1,0,0))

Finally I've requested the estimated coefficients

> wnF$coef
         ar1    intercept 
-0.003655755  0.108935363 

Now I want to replicate the computation R. I exported the data to an Excel file (https://www.dropbox.com/s/6c8ukcbtxe9gqp1/DataTester.xlsx?dl=0) and computed the following model:

$$
x{_t}-\mu = \psi_1x_{t-1}+\omega_t
$$

I've replaced $\mu$ and $\psi_1$ with the intercept and ar1 coefficients reported by the wnF$coef command. I've also replaced $\omega_t$ with zero, since I've sampled the data from a zero-mean population.

Finally I've compared the residuals from the R computed model (wnF$residuals) with the residuals I've computed in the Excel file and I've noticed that they differ about $\delta<0.0005$ in absolute value.

I know that 0.0005 is not much, but when dealing with such small values it may not be negligible.

I also find strange that there is no difference up the fourth decimal place.

Can you please help me finding the origin of the difference?

Best Answer

After some research I found out that the difference between R computed residuals given by wnF$residuals and the residuals I've computed externaly in Excel file, was originated from the lack of precision of the data passed to Excel.

At first, I had passed data to Excel with only 7 decimal places. After repeating the procedure with 15 decimal places, the difference almost disapeared.

Also, as Richard Hardy commented, the model I was fitting was not correct. The correct model is:

$$ x_t-\mu=\psi_1(x_{t-1}-\mu)+\omega_t $$