[R] Re gression for levels of a factor/xyplot type="r"
ggrothendieck at gmail.com
Thu Oct 1 06:13:39 CEST 2009
See lmList in the lme4 package. Each component of the result will be
one lm and you can take a summary of each.
On Wed, Sep 30, 2009 at 11:10 PM, jimdare <jamesdare26 at gmail.com> wrote:
> I'm sure these are basic problems so I apologise in advance for my
> ignorance. I have a dataset with X, Y, and a Factor with 4 levels. I am
> trying to figure out how to use lm() to find the r2 value, slope and
> intercept of an X~Y regression, for each level of the Factor. Is there a
> way to do this automatically without having to specify different subsets of
> the factor?
> my code so far:
> Regression<-lm(Y~X, data=dataset, subset=factor(Factor))
> Also, when I plot this dataset using:
> xyplot(Y~X|factor(Factor), data=dataset, aspect="iso",
> I get a four panel plot (one for each level of the factor) with a regression
> line for each. How do I figure out the r2 value and coefficients of each
> regression line and add them as text to the plot.
> Thanks for your help!
> View this message in context: http://www.nabble.com/Regression-for-levels-of-a-factor-xyplot-type%3D%22r%22-tp25692526p25692526.html
> Sent from the R help mailing list archive at Nabble.com.
> 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.
More information about the R-help