1

I would like to know if I could have only specific components of the R Summary output to be displayed. From the output below, I would like only the F-statistic (or only the following line-F-statistic: 0.834 on 2 and 10 DF, p-value: 0.4624) to be displayed. I am actually dealing with an imputed data and trying to extract this value from a series of summary outputs.

Thank you!

 > hanes=with(nhanes, lm(bmi~hyp+chl))
 > summary(hanes)
 Call:
 lm(formula = bmi ~ hyp + chl)

 Residuals:
 Min     1Q Median     3Q    Max 
-6.425 -3.296  0.035  3.123  7.632 

 Coefficients:
 Estimate Std. Error t value Pr(>|t|)   
 (Intercept) 20.10564    5.70716   3.523  0.00551 **
 hyp         -0.68459    3.39596  -0.202  0.84428   
 chl          0.03783    0.03054   1.239  0.24370   
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 4.66 on 10 degrees of freedom
 (12 observations deleted due to missingness)
 Multiple R-squared:  0.143,    Adjusted R-squared:  -0.02846 
 F-statistic: 0.834 on 2 and 10 DF,  p-value: 0.4624

UPDATE WITH REPRODUCIBLE EXAMPLE WITH NHANES2 DATA IN R:

  > imp10=mice(nhanes2, m=10, seed=11111)

  > hanes=with(imp10, lm(bmi~hyp+chl))

  > summary(hanes)

above yields summary for each of the 10 imputations:

  ## summary of imputation 1 :

  Call:
  lm(formula = bmi ~ hyp + chl)

  Residuals:
  Min      1Q  Median      3Q     Max 
  -7.4597 -3.1938  0.1403  2.8153  7.0753 

  Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
  Intercept) 19.30988    4.47439   4.316 0.000279 ***
  hyp2        -0.38202    2.41568  -0.158 0.875789    
  chl          0.04265    0.02398   1.779 0.089101 .  
  ---
  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

  Residual standard error: 4.332 on 22 degrees of freedom
  Multiple R-squared:  0.1425,  Adjusted R-squared:  0.06456 
  F-statistic: 1.828 on 2 and 22 DF,  p-value: 0.1843

The fs=summary(hanes)$fstatistic code still produces complete summary. Thank you again!

user81715
  • 67
  • 1
  • 1
  • 11
  • `summary(mode)$fstatistic` with `mode` is the name of your fitted model. it should work but for more precise answers next time please post a reproducible example. See [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) how to create it. – SabDeM Jul 30 '15 at 14:41
  • I can see that a reproducible example would have been useful here. The command works for a non-imputed dataset but for an imputed set I am working with it is still producing the complete set of results. Thanks for your help. – user81715 Jul 30 '15 at 14:56
  • You should be aware that there is no such thing as `summary` in R. In your case, type `class(hanes)`, and it will tell you that the class is `lm`. So `summary(hanes)` effectively calls `summary.lm(hanes)`. Try to enter `summary.lm` without () to find out what done behind the curtain. – Dieter Menne Jul 30 '15 at 14:56

1 Answers1

1

As following to my comment:

to retrive the F-statistic you may use:

fs <- summary(mode)$fstatistic

and the P values associate with it:

pva <- anova(mode)$"Pr(>F)"[1]

and then combine together with a sprintf etc. Or just use capture.output that save all the outputs in a character vector where each element corresponds to a line; you have just to take the line of interest, in this case the 18:

capture.output(summary(mode))[18]
[1] "F-statistic: 30.19 on 1 and 30 DF,  p-value: 5.766e-06"

I have used a fitted model with the mtcars dataset in R.

SabDeM
  • 7,050
  • 2
  • 25
  • 38