Skip to main content

I dont quite understand the answer given in Order of variables in R lm model In lmin 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=a seq= seq(1:100)+rnorm + rnorm(100, sd=5)
    b=b seq= seq(0.01:0.99, by=0.01)+rnorm + rnorm(100, sd=3)/100
    c=c = seq(1:100)+rnorm + rnorm(100, sd=3)
    d=d = seq(1:100)+rnorm + rnorm(100, sd=3)
    summary(lm(a~c+b+d))
    summary(lm(a~b+c+d))

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

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))
Tweeted twitter.com/StackStats/status/1339767491283841025
Became Hot Network Question
edited tags
Link
Christoph Hanck
  • 34.8k
  • 3
  • 78
  • 137
Source Link
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))