[R] Using xlevels

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 30 17:36:19 CEST 2011


On Wed, 30 Mar 2011, Terry Therneau wrote:

> I'm working on predict.survreg and am confused about xlevels.
> The model.frame method has the argument, but none of the standard
> methods (model.frame.lm, model.frame.glm) appear to make use of it.

But I see this in predict.lm:

         m <- model.frame(Terms, newdata, na.action = na.action,
                          xlev = object$xlevels)

It is used to remap levels in newdata to those used in the fit.

>
> The documentation for model.matrix states:
>  xlev: to be used as argument of model.frame if data has no "terms"
> attribute.

Well, the code says

     if (is.null(attr(data, "terms")))
         data <- model.frame(object, data, xlev=xlev)

> But the terms attribute has no xlevels information in it, so I find this
> statement completely confusing.  Any insight is appreciated.

It means exactly what it says: a 'data' argument with a terms 
attribute is considered to be a model frame.

>
> Terry Therneau
>
> ______________________________________________
> R-help at 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.
>

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