# 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)
ar(x)


result is

Coefficients:
1
0.5531


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?

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.

ar.ols(x,demean=FALSE)

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

Coefficients:
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 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)
#Coefficients:
#x1  x2
# 1   1


Answered by Zheyuan Li on January 5, 2022

## Related Questions

### Should I balance the classifier train/test set, if metrics is Precision/Recall (F1 score)?

1  Asked on November 2, 2021 by data-man

### Assumption logistic regression: linearity of independent variables and log odds?

0  Asked on November 2, 2021 by franziska

### lme4: Three-Level Autoregressive Model – Random Effects

1  Asked on November 2, 2021 by s_haring

### How many ways are there to select exactly one heart in a hand of 5?

3  Asked on March 9, 2021 by pythonnoob

### The behaviour of dice loss when target and prediction are disjoint

0  Asked on March 4, 2021 by bmurray

### Loss function for regression

1  Asked on March 3, 2021

### What is a generalized linear model

0  Asked on March 2, 2021 by pluviophile

### Help with choosing appropriate way to test hypothesis

1  Asked on March 2, 2021 by sleepy

### Identifiability of multinomial logistic regression

0  Asked on March 1, 2021 by sedi

### How to calculate the ACF and PACF for time series

2  Asked on February 28, 2021 by peterbe

### Represent Integer Categorical feature as both Numeric and Categorical

0  Asked on February 27, 2021 by user2991421

### Determine the test statistic for each case

1  Asked on February 27, 2021 by mathslover

### Statistical test whether to use Sharp or Fuzzy Regression Discontinuity Design

1  Asked on February 27, 2021 by misologie

### Conditional and unconditional expectation for the variance of error term in linear regression

1  Asked on February 25, 2021 by mcgurck

### Python Fastai library – Loss and Validation interpretation

0  Asked on February 25, 2021 by la_haine

### How to estimate Standard error with delta method

0  Asked on February 24, 2021 by zge

0  Asked on February 24, 2021 by diricksen

### 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