[R] Extracting values from linear models

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Fri Feb 18 00:23:37 CET 2005


Assume that you have stored the lm object as 'fit' and the summary as
fit.summ as such

 x   <- rnorm(100)
 y   <- rnorm(100)
 fit <- lm( y ~ x )
 fit.summ <- summary( fit )

fit.summ$coefficients and fit.summ$adj.r.squared gives you the
coefficients and adjusted R-square.

names( fit.summ ) or str( fit.summ ) will give further clue as how
fit.summ looks like.

Regards, Adai


On Thu, 2005-02-17 at 15:12 -0700, Heather Maughan wrote:
> 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?
> 
> Thanks,
> Heather




More information about the R-help mailing list