Using the lm function of R to solve the autocorrelation problem

Asked

Viewed 211 times

0

I’m working with the function.

lm(y~x)

simple regression, due to tests I checked autocorrelation, so the blibliography indicates a transformation. Something like:

Y=B1*(1-p)+B2(X-(p*X[-1]))

That would be the application of correction P in the model, being that P is known to me. Someone knows a technique of autocorrelation correction, next to the function presented?

Thank you

  • 1

    If there is autocorrelation in the data, why not use the weapon model?

  • Marcus, it’s a multivariate would and I don’t know how to program for more than one explanatory variable. but it is quite possible to be solved with an ARIMA 2,1,2

  • Then use a VARIMA (ARIMA Vector). I suggest not trying to reinvent the wheel.

  • How would you program that in R?

1 answer

3


If this is a time series, it’s best to work with https://cran.r-project.org/web/views/TimeSeries.html, but if you really want to do this, then: create a delay column (lag) and p-value
lag<-x
lag<-c(NA, test)
P<-rep.int(p, length(test))

example:

> te<-1:10
> te
 [1]  1  2  3  4  5  6  7  8  9 10
> te<-c(NA,te)
> te
 [1] NA  1  2  3  4  5  6  7  8  9 10
>p<-rep.int(0.3, length(te))

And make lm to estimate B1 and B2:

lm(y~(1-P)+(X-(P*te))

Just be careful, because all columns should be the same size.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.