[R] Specifying xlevels in effects library

John Fox jfox at mcmaster.ca
Wed Jun 9 18:47:39 CEST 2004


Dear David and Andy,

First, my apologies for somehow missing the original message.

Andy has it right: xlevels refers to the predictors in the term
corresponding to the effect to be computed. His solution is clever -- I
wouldn't have thought of it -- but it could get you into trouble in a
more complicated model.

Another possibility is to specify an effect that includes both
predictors (i.e., the Sex*Age effect, which is higher-order to the
terms actually in the model), and to set Age to the desired value in
xlevels. At present, effect() wants more than one value for each
variable in the xlevels list. I'll look at changing that, but at
present you could do something like

effect("Sex*Age", mod, xlevels=(Age=c(120,120)))

This should get you what you want, albeit redundantly.

I hope that this helps,
 John


On Wed, 9 Jun 2004 09:40:49 -0400
 "Liaw, Andy" <andy_liaw at merck.com> wrote:
> Prof. Fox will be able to give the definitive answer, but from my
> reading of
> ?effect, xlevels refers to the values of the factor whose effect
> you're
> interested in, not the ones being `marginalized'.  I believe you need
> to
> play with the `typical' argument.
> 
> HTH,
> Andy
> 
> > From: David J. Netherway
> > 
> > library(effects)
> > mod <- lm(Measurement ~ Age + Sex, data=d)
> > e <-effect("Sex",mod)
> >  
> > The effect is evaluated at the mean age.
> >  
> >  > e
> > Sex effect
> > Sex
> >        F        M  
> > 43.33083 44.48531  
> >  >
> >  > e$model.matrix
> >    (Intercept)      Age SexM
> > 1            1 130.5859    0
> > 23           1 130.5859    1
> >  
> > To evaluate the effect at Age=120 I tried:
> > e <-effect("Sex",mod,xlevels=list(Age=c(120)))
> > but the effect was still evaluated at 130.5859.
> >  
> > Is this an incorrect usage of xlevels?
> > 
> > Thanks, David
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! 
> > http://www.R-project.org/posting-guide.html
> > 
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html


--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/




More information about the R-help mailing list