[R] [r] regression coefficient for different factors
Robert Baer
rbaer at atsu.edu
Fri May 20 15:07:59 CEST 2011
?summary
produces r^2 in 2nd to last line, as in,
> set.seed(12); a=rnorm(100); b = runif(100); c = factor(rep(c('No',
> 'Yes'),50)); df = data.frame(a,b,c)
> head(df)
a b c
1 -1.4805676 0.9729927 No
2 1.5771695 0.2172974 Yes
3 -0.9567445 0.5205087 No
4 -0.9200052 0.8279428 Yes
5 -1.9976421 0.9641110 No
6 -0.2722960 0.6318801 Yes
> mod = lm(a ~ b*c)
> summary(mod)
Call:
lm(formula = a ~ b * c)
Residuals:
Min 1Q Median 3Q Max
-1.8196 -0.4754 -0.0246 0.5585 2.0941
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.2293 0.2314 0.991 0.324
b -0.4226 0.3885 -1.088 0.280
cYes 0.1578 0.3202 0.493 0.623
b:cYes -0.5878 0.5621 -1.046 0.298
Residual standard error: 0.8455 on 96 degrees of freedom
Multiple R-squared: 0.07385, Adjusted R-squared: 0.04491
F-statistic: 2.552 on 3 and 96 DF, p-value: 0.0601
------------------------------------------
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A. T. Still University of Health Sciences
800 W. Jefferson St.
Kirksville, MO 63501
660-626-2322
FAX 660-626-2965
--------------------------------------------------
From: "Francesco Nutini" <nutini.francesco at gmail.com>
Sent: Friday, May 20, 2011 4:17 AM
To: "[R] help" <r-help at r-project.org>
Subject: [R] [r] regression coefficient for different factors
>
> Dear R-helpers,
>
> In my dataset I have two continuous variable (A and B) and one factor.
> I'm investigating the regression between the two variables usign the
> command
> lm(A ~ B, ...)
> but now I want to know the regression coefficient (r2) of A vs. B for
> every factors.
> I know that I can obtain this information with excel, but the factor have
> 68 levels...maybe [r] have a useful command.
>
> Thanks,
>
> Francesco Nutini
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list