[R] Using xlevels

Terry Therneau therneau at mayo.edu
Wed Mar 30 19:28:30 CEST 2011


I see the logic now.  I think that more sentences in the document would
be very helpful, however.  What is written is very subtle.
I suggest the following small expansion for model.matrix.Rd:

  \item{data}{a data frame.  If the object has a \code{terms} attribute
then it is assumed to be the result of a call to \code{model.frame},
otherwise \code{model.frame} will be called first.}

 I often forget that model.frames are not a class, but an "implied"
class based on the presence of a terms component.  Many users, I
suspect, do not even have this starting knowledge.

  Off to make changes to model.frame.coxph and model.matrix.coxph...

Thanks for the feeback.

	Terry


On Wed, 2011-03-30 at 16:36 +0100, Prof Brian Ripley wrote:
> 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.
> >
>



More information about the R-help mailing list