How does autoregression work in R?

Cross Validated Asked on January 5, 2022

I don’t understand results of ar() function in R.

I made up a very simple case, Fibonacci sequence:

x <- c(1,1,2,3,5,8,13,21,34,55)

result is


I would expect result of 1,1 – for the model x(n) = 1* x(n-1) + 1 * x(n-2)

Can anyone explain me please why I don’t get expected result?

2 Answers

You may use ar.ols to estimate this non-stationary series.

From the docs,

ar.ols fits the general AR model to a possibly non-stationary and/or multivariate system of series x.

Example with your data:


ar.ols(x = x, demean = FALSE)

1  2  
1  1 

Answered by A. Webb on January 5, 2022

As I said in my comment, you are going toward a wrong direction.

ar is assuming x as a stationary process AR(p). The default estimation method "yule-walker" is a moment estimator. Please see Yule-Walker equations of autoregressive process for more.

ar selects order p by minimizing AIC. For you example Fibonacci sequence x, it has selected p = 1. The resulting coefficient, by Yule-Walker equations, matches the sample ACF at lag 1:

z <- acf(x, lag.max = 1)
#    0     1
#1.000 0.553

enter image description here

Since model assumption is wrong, you definitely can not get c(1, 1) as the answer. A crude way to get you to the right estimation is using least squares linear regression:

N <- length(x)
y <- x[3:N]
x1 <- x[2:(N-1)]    # lag-1 
x2 <- x[1:(N-2)]    # lag-2

lm(y ~ x1 + x2 - 1)  ## drop intercept (as you know it for sure)
#x1  x2  
# 1   1  

Answered by Zheyuan Li on January 5, 2022

Add your own answers!

Related Questions

Stationarity in SAS

0  Asked on March 13, 2021 by adrcoder


What is a generalized linear model

0  Asked on March 2, 2021 by pluviophile


SVM-Light displays corrupted precision/recall results

1  Asked on February 24, 2021 by zvisofer


bounds test for cointegration (Pesaran ardl)

2  Asked on February 23, 2021 by user54285


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP