Dimitri Liakhovitski
2010-Oct-18 21:15 UTC
[R] Question about lme (mixed effects regression)
Hello! If I run this example: library(nlme) fm1 <- lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example, for MO1 it's: 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. So, in order to get the the total effects, i.e., the regression equation, for each subgroup (Subject) I need to do this: For example, for Subject MO1: y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 + 0.766*Age -3.18*SexFemale Question: Is there an easier way to get such an equation for each level of Subject? Thank you very much! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com
Dmitri: Not quite sure what you mean by easier ... fixef() and ranef() will both give coefficients which can be easily manipulated to produce the results for all subjects. However, note that there are numerous built-in lme functions(especially for graphics) that do this internally to produce, e.g. graphs of coefficient shrinkage. So if this is the sort of thing you want to do with the BLUPS, you may not need to do it manually. HTH. Cheers, Bert On Mon, Oct 18, 2010 at 2:15 PM, Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:> Hello! > > If I run this example: > > library(nlme) > fm1 <- lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) > If I run: > summary(fm1) > then I can see the fixed effects for age and sex (17.7 for intercept, > 0.66 for age, and -1.66 for SexFemale) > > If I run: > ranef(fm1) > Then it looks like it's producing the random effects for each subgroup > (in this example - each subject). For example, for MO1 it's: > 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. > > So, in order to get the the total effects, i.e., the regression > equation, for each subgroup (Subject) I need to do this: > For example, for Subject MO1: > y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 > + 0.766*Age -3.18*SexFemale > > Question: Is there an easier way to get such an equation for each > level of Subject? > > Thank you very much! > > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > > ______________________________________________ > 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. >-- Bert Gunter Genentech Nonclinical Biostatistics
Possibly Parallel Threads
- formula, how to express for transforming the whole model.matrix, data=Orthodont
- Code is too slow: mean-centering variables in a data frame by subgroup
- Question about mixed-effects models example (Pinheiro and Bates)
- summing values by week - based on daily dates - but with some dates missing
- xyplot: adding pooled regression lines to a paneled type="r" plot