[R] lags in regressions

Tobias Mühlhofer t.muhlhofer at lse.ac.uk
Fri Jan 23 18:58:19 CET 2004


I am trying to get R to run regressions for me of a variable on lagged 
differences of itself.


x-x(-1) = a + b1(x(-1)-rx(-2))+b2(x(-4)-rx(-5))+e

I need to do this a lot of times, altering the value of r.

What I've been trying to do was to use the lag() command to create 
lagged versions of these variables and then constructing these 
differences by hand (i.e. creating new variables containing these 

When I put all of those into the lm() command I get a singularity 
problem: it seems that R is unlagging the time series as it constructs 
the object matrix, instead of simply truncating away observations that 
don't exist for all the series due to the "pushing over" that is 
happening in the lagging.

What do I do? Do I need to truncate these by hand and if yes how? Or is 
there a different way?

When Thomas Edison invented the light bulb he tried over 2000 experiments
before he got it to work. A young reporter asked him how it felt to have
failed so many times. He said "I never failed once. I invented the light
bulb. It just happened to be a 2000-step process."

More information about the R-help mailing list