[R] names of model coefficients etc
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Sep 28 15:44:43 CEST 2001
On Fri, 28 Sep 2001, David Firth wrote:
> I am curious about the reason for the following:
>
> > xzw<-lm(y ~ x+cbind(z,w))
> > names1<-names(xzw$coefficients)
> > names1
> [1] "(Intercept)" "x" "cbind(z, w)z" "cbind(z, w)w"
> > names2<-colnames(as.matrix(xzw$model))
> > names2
> [1] "y" "x" "cbind(z, w).z" "cbind(z, w).w"
> > names1==names2
> [1] FALSE TRUE FALSE FALSE
>
> It would be helpful for some purposes if all components except the
> first here could be TRUE. Presumably there is some good reason for
> the difference? Can someone please enlighten me?
xzw$model is the model frame: xzw$coefficients refers to the model
matrix. With factors in the model they are very different.
I guess you wanted a linear model fit with x=TRUE and xzw$x, as it
y <- rnorm(100)
x <- rnorm(100)
z <- rnorm(100)
w <- rnorm(100)
xzw<-lm(y ~ x+cbind(z,w), x = TRUE)
colnames(xzw$x)
[1] "(Intercept)" "x" "cbind(z, w)z" "cbind(z, w)w"
Further, be careful of calling xzw$coefficients rather than coef(xzw).
You will not always get the same thing with other fitting functions.
Brian
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list