[R] Specifying xlevels in effects library
Liaw, Andy
andy_liaw at merck.com
Wed Jun 9 15:56:14 CEST 2004
Here's an example:
> library(effects)
> age <- round(rnorm(100, mean=30, sd=5))
> sex <- factor(sample(c("M","F"), 100, replace=TRUE))
> y <- rnorm(100)
> fit <- lm(y ~ age + sex)
> eff <- effect("sex", fit, typical=function(...) 25)
> eff
sex effect
sex
F M
-0.23387685 0.07063834
Now we can check if that looks right:
> predict(fit, newdata=data.frame(age=c(25, 25), sex=factor(c("M","F"))))
1 2
0.07063834 -0.23387685
HTH,
Andy
> From: Liaw, Andy
>
> 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
>
>
> --------------------------------------------------------------
> ----------------
> Notice: This e-mail message, together with any attachments,
> contains information of Merck & Co., Inc. (One Merck Drive,
> Whitehouse Station, New Jersey, USA 08889), and/or its
> affiliates (which may be known outside the United States as
> Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as
> Banyu) that may be confidential, proprietary copyrighted
> and/or legally privileged. It is intended solely for the use
> of the individual or entity named on this message. If you
> are not the intended recipient, and have received this
> message in error, please notify us immediately by reply
> e-mail and then delete it from your system.
> --------------------------------------------------------------
> ----------------
>
More information about the R-help
mailing list