Michael Friendly
2010-Jun-22 16:30 UTC
[R] xyplot: adding pooled regression lines to a paneled type="r" plot
Consider the following plot that shows separate regression lines ~ age for each subject in the Pothoff-Roy Orthodont data, with separate panels by Sex: library(nlme) #plot(Orthodont) xyplot(distance ~ age|Sex, data=Orthodont, type='r', groups=Subject, col=gray(.50), main="Individual linear regressions ~ age") I'd like to also show in each panel the pooled OLS regression line for each Sex in the corresponding panel, generated by the following model: Ortho.OLS <- lm(distance ~ age * Sex, data=Orthodont) Sex is a factor, with Male=0, so the coefficients are: > coef(Ortho.OLS) (Intercept) age SexFemale age:SexFemale 16.3406250 0.7843750 1.0321023 -0.3048295 I anticipate wanting to fit other models to these data, and also displaying the model-predicted regression lines in the same or similar plot, e.g., for a simple linear mixed model: Ortho.MLM <- lme(distance ~ age * Sex, data=Orthodont, random = ~ 1 + age | Subject, correlation = corAR1 (form = ~ 1 | Subject)) TIA, -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
RICHARD M. HEIBERGER
2010-Jun-22 16:45 UTC
[R] xyplot: adding pooled regression lines to a paneled type="r" plot
Michael, Look at the ancova function in the HH package. ## install.packages("HH") ## if not there yet. library(HH) library(nlme) ## for the Orthodont data ancova(distance ~ age*Sex, data=Orthodont) ancova(distance ~ age+Sex, data=Orthodont) ancova(distance ~ age, groups=Sex, data=Orthodont) ancova(distance ~ Sex, x=age, data=Orthodont) Rich On Tue, Jun 22, 2010 at 12:30 PM, Michael Friendly <friendly@yorku.ca>wrote:> Consider the following plot that shows separate regression lines ~ age for > each subject in the Pothoff-Roy Orthodont data, > with separate panels by Sex: > > library(nlme) > #plot(Orthodont) > xyplot(distance ~ age|Sex, data=Orthodont, type='r', groups=Subject, > col=gray(.50), > main="Individual linear regressions ~ age") > > I'd like to also show in each panel the pooled OLS regression line for each > Sex in the corresponding panel, > generated by the following model: > > Ortho.OLS <- lm(distance ~ age * Sex, data=Orthodont) >[[alternative HTML version deleted]]
Deepayan Sarkar
2010-Jun-22 19:32 UTC
[R] xyplot: adding pooled regression lines to a paneled type="r" plot
On Tue, Jun 22, 2010 at 9:30 AM, Michael Friendly <friendly at yorku.ca> wrote:> Consider the following plot that shows separate regression lines ~ age for > each subject in the Pothoff-Roy Orthodont data, > with separate panels by Sex: > > library(nlme) > #plot(Orthodont) > xyplot(distance ~ age|Sex, data=Orthodont, type='r', groups=Subject, > col=gray(.50), > ? main="Individual linear regressions ~ age") > > I'd like to also show in each panel the pooled OLS regression line for each > Sex in the corresponding panel, > generated by the following model: > > Ortho.OLS <- lm(distance ~ age * Sex, data=Orthodont) > > Sex is a factor, with Male=0, so the coefficients are: >> coef(Ortho.OLS) > ?(Intercept) ? ? ? ? ? age ? ? SexFemale age:SexFemale > ?16.3406250 ? ? 0.7843750 ? ? 1.0321023 ? ?-0.3048295 > > I anticipate wanting to fit other models to these data, and also displaying > the model-predicted > regression lines in the same or similar plot, e.g., for a simple linear > mixed model: > > Ortho.MLM <- lme(distance ~ age * Sex, data=Orthodont, > ? ? ? random = ~ 1 + age | Subject, > ? ? ? correlation = corAR1 (form = ~ 1 | Subject))Have a look at http://user2007.org/program/presentations/sarkar.pdf -Deepayan
Maybe Matching Threads
- Sweave: infelicities with lattice graphics
- xyplot: key inside the plot region / lme: confidence bands for predicted
- Question about lme (mixed effects regression)
- Question about mixed-effects models example (Pinheiro and Bates)
- formula, how to express for transforming the whole model.matrix, data=Orthodont