[R] xyplot: adding pooled regression lines to a paneled type="r" plot

From: Michael Friendly <friendly_at_yorku.ca>
Date: Tue, 22 Jun 2010 12:30:58 -0400

Consider the following plot that shows separate regression lines ~ age for each subject in the Pothoff-Roy Orthodont data, with separate panels by Sex:

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))


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

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 22 Jun 2010 - 16:31:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jun 2010 - 21:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive