Hi:

On Thu, Dec 23, 2010 at 4:37 PM, Tautz, Art ENV:EX <Art.Tautz@gov.bc.ca>wrote:

> Dear list
>
> I am sorry to have to ask this  question, but I have not been able to
> find a solution to what seems a simple problem.  I have created a
> lattice plot of
> a number of regression points and lines using a function containing
> panel.xyplot  and panel.lmline.  The result is what is expected , but I
> cannot figure out how to obtain the coefficients of each of the
> regression lines.   Any help would be appreciated.
>

Here's one (albeit roundabout) way to get the coefficients using the lsfit()
function, assuming that we're discussing simple linear regression; you need
to adapt it a bit if you want multiple regression.

dd <- data.frame(gp = factor(rep(LETTERS[1:10], each = 50)),
           x = rnorm(500, 10, 5),
           y = rep(1:10, each = 50) + 2 * rnorm(500, 10, 5) + rnorm(500, 0,
0.5))
sl <- split(dd[, -1], dd$gp)
do.call(rbind, lapply(sl, function(d) lsfit(d$x, d$y)$coef))

or more simply, using package plyr,

library(plyr)
ddply(dd, .(gp), function(d) lsfit(d$x, d$y)$coef)

HTH,
Dennis

>
> Art Tautz
> Science Advisor
> 2202 Main Mall UBC
> Ministry of Environment
> University of British Columbia
> Vancouver BC Canada  V6T 1Z4
> Phone 604-222-6763
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

