[R] is.null() and lm obj

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Tue Feb 11 15:52:08 CET 2003


Partial matching!

obj$x matches obj$xlevels.  You need to use obj[["x"]] to be sure to
get exactly that component.

Why didn't you try

> names(obj)
 [1] "coefficients"  "residuals"     "effects"       "rank"         
 [5] "fitted.values" "assign"        "qr"            "df.residual"  
 [9] "xlevels"       "call"          "terms"         "model"        
> obj$x
list()

?

On Tue, 11 Feb 2003, vito muggeo wrote:

> I found the following strange behavior of is.null() in the x component of a
> lm object.
> *However note that I'm running R-1.5.1, so probably the error (if someone)
> has been fixed in the the versions 1.6.x. If it is so, please apologizes for
> this my e-mail
> 
> x<-1:10
> y<-rnorm(10)
> obj<-lm(y~x)
> >is.null(obj$y)
> [1] TRUE
> >is.null(obj$x)
> [1] FALSE
> >dim(obj$x)
> NULL
> 
> That is, according to "is.null(obj$x)" the design matrix seems to be present
> in the lm object, but it is not so, of course. "is.null(obj$y)" seems to
> work correctly.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list