Hi
Say I want to add manually an intercept in the function lm. Even if
almost all results will be identical, few stats are different as DF
counting will be different as intercept will not be included in
"automatic" case, while it will be in "manual" case. See:
###usual lm on freeny
fr<-lm(freeny.y~freeny.x)
###manual lm on freeny
man<-cbind(1,freeny.x)
colnames(man)<-c("const",colnames(freeny.x))
fr_man<-lm(freeny.y~man-1)
###coef are the same
cbind(coef(fr), coef(fr_man))
###but summary output is different (but should be the same!).
#Difference comes from fact that in the "automatic case", DF are 4
(intercept not included)
summary(fr)
summary(fr_man)
###Workaround:
attr(fr_man$terms, "intercept") <- 1
##so now:
summary(fr)
summary(fr_man)
###but have negative effect that intercept is used twice in
model.matrix, see:
model.matrix(fr_man)
So I could not find a good way to add manually an intercept and
preserving the right output... any idea?
Thanks a lot!!
Matthieu Stigler
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.