Skip to main content
1 of 3
biofan
  • 137
  • 1
  • 5

Order of variables in R's lm

I dont quite understand the answer given in Order of variables in R lm model In lm function of R (and generally formulas) why changing the order of variable matters? My own guess is that the model first calculates the effect of first variable, and then uses the second variable for remaining variation in dependent variable and so on.

set.seed(1)
a= seq (1:100)+rnorm(100, sd=5)
    b= seq (0.01:0.99, by=0.01)+rnorm(100, sd=3)/100
    c= seq(1:100)+rnorm(100, sd=3)
    d= seq(1:100)+rnorm(100, sd=3)
    summary(lm(a~c+b+d))
    summary(lm(a~b+c+d))
biofan
  • 137
  • 1
  • 5