[R] Extract information from the summary of 'lm'
ronggui
ronggui.huang at gmail.com
Wed Jun 21 04:43:40 CEST 2006
> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
> group <- gl(2,10,20, labels=c("Ctl","Trt"))
> weight <- c(ctl, trt)
> lm.D9 <- lm(weight ~ group)
> summary(lm.D9)$coef
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.032 0.2202177 22.850117 9.547128e-15
groupTrt -0.371 0.3114349 -1.191260 2.490232e-01
> class(summary(lm.D9)$coef)
[1] "matrix"
> colnames(summary(lm.D9)$coef)
[1] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
So you can get t and p-value by
>summary(lm.D9)$coef[,"t value"]
> summary(lm.D9)$coef[,"Pr(>|t|)"]
If you want to get the result as matrix,just use the drop=F argument.
> summary(lm.D9)$coef[,"Pr(>|t|)",drop=F]
Pr(>|t|)
(Intercept) 9.547128e-15
groupTrt 2.490232e-01
2006/6/21, Jun Ding <dingjun_cn at yahoo.com>:
> Hi Everyone,
>
> I just don't know how to extract the information I
> want from the summary of a linear regression model
> fitting.
>
> For example, I fit the following simple linear
> regression model:
>
> results = lm(y_var ~ x_var)
>
> summary(results) gives me:
>
> Call:
> lm(formula = y_var ~ x_var)
>
> Residuals:
> Min 1Q Median 3Q Max
> -5.9859 -1.5849 0.4574 2.0163 4.6015
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) -1.7782 0.5948 -2.990 0.004879 **
> x_var 2.1237 0.5073 4.187 0.000162 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.'
> 0.1 ' ' 1
>
>
> I can get the esitmates (i.e. -1.7782 and 2.1237) of
> coefficients by calling
>
> results$coefficients
I think using coef(result) is a better habit.
> But I don't know how to get the corresponding t values
> and P values for those coefficients. I am running a
> lot of regression models and I can not run 'summary'
> every time to get the t and P values for each model.
>
> Can anybody give me some hints? Thank you very much!
>
> Best,
>
> Jun
>
> ----------------------------
> Jun Ding, Ph.D. student
> Department of Biostatistics
> University of Michigan
> Ann Arbor, MI, 48105
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
»ÆÈÙ¹ó
Department of Sociology
Fudan University
More information about the R-help
mailing list