[R] Extracting values from linear models

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Feb 18 00:01:05 CET 2005


Heather Maughan <hmaughan at u.arizona.edu> writes:

> Hello:
> 
> I want to use values from the output of linear models done using permuted
> data to construct a random distribution.  The problem I am having is the
> extraction of a value, say the p-value or the regression coefficient, from
> the summary of a linear model. When summarizing a linear model I get this:
> 
> Call:
> lm(formula = fitness ~ mm)
> 
> Residuals:
>      Min       1Q   Median       3Q      Max
> -0.57369 -0.17551 -0.01602  0.15723  0.68844
> 
> Coefficients:
>              Estimate Std. Error t value Pr(>|t|)
> (Intercept)  1.783440   0.074052  24.084  < 2e-16 ***
> mm          -0.004272   0.001456  -2.933  0.00662 **
> ---
> Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> 
> Residual standard error: 0.3261 on 28 degrees of freedom
> Multiple R-Squared: 0.2351,    Adjusted R-squared: 0.2077
> F-statistic: 8.604 on 1 and 28 DF,  p-value: 0.006621
> 
> How do I pick out the p-value, or the R-squared using R code?

Take a look inside the print method for summary.lm objects
(getAnywhere(print.summary.lm)). Notice that the the x$fstatistic is
there but the p value is being calculated by the print method.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list