Using the function lm, from R, to solve the problem autocorrelation

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]))

What would be the application of the correction P in the model, where P is known by me. Does anyone know an autocorrelation correction technique, next to the given function?

Thank you

    
asked by anonymous 28.04.2018 / 21:11

1 answer

3

If this is a time series, it's best to work with link , but if you really want to do this, then: create a column of delays (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 do lm to estimate B1 and B2:

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

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

    
30.04.2018 / 21:28