Skip to content
Prev 319200 / 398506 Next

quesion about lm function

Hi
You did not read the full advice.
The above results (means) are correct at x1 and x2 = 0.

result_lm <- lm(y~0+factor(sex) + scale(x1) + scale(x2), data=test)
coef(result_lm)
factor(sex)f factor(sex)m    scale(x1)    scale(x2) 
   3876.6290    4013.4576     945.5634     592.7385 

Anyway not a big difference from

tapply(test$y, test$sex, mean)
       f        m 
3790.760 4099.327 

Regards
Petr