max
max

Reputation: 25

Extracting selected output in R using summary

Extracting selected output in R using summary

model <- glm(am ~ disp + hp, data=mtcars, family=binomial)
T1<-summary(model)
T1

This is the output i get

 Call:
    glm(formula = am ~ disp + hp, family = binomial, data = mtcars)
    
    Deviance Residuals: 
        Min       1Q   Median       3Q      Max  
    -1.9665  -0.3090  -0.0017   0.3934   1.3682  
    
    Coefficients:
                Estimate Std. Error z value Pr(>|z|)  
    (Intercept)  1.40342    1.36757   1.026   0.3048  
    disp        -0.09518    0.04800  -1.983   0.0474 *
    hp           0.12170    0.06777   1.796   0.0725 .
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    (Dispersion parameter for binomial family taken to be 1)
    
    Null deviance: 43.230  on 31  degrees of freedom
    Residual deviance: 16.713  on 29  degrees of freedom
    AIC: 22.713
    
    Number of Fisher Scoring iterations: 8

I want to extract only the coefficients and null deviance as shown below how do I do it, I tried using $coefficeint but it only shows coefficient values ?

Coefficients:
(Intercept)        disp          hp 
1.40342203   -0.09517972      0.12170173 

Null deviance: 43.230  on 31  degrees of freedom
Residual deviance: 16.713  on 29  degrees of freedom
AIC: 22.713

Upvotes: 1

Views: 458

Answers (1)

TarJae
TarJae

Reputation: 78927

Update: Try this:

  coef(model)
  model$coefficients
  model$null.deviance
  model$deviance
  model$aic

If you type in T1$ then a window occurs and you can select whatever you need.

  T1$null.deviance    
  T1$coefficients
>   T1$null.deviance        
[1] 43.22973
>   T1$coefficients
               Estimate Std. Error   z value   Pr(>|z|)
(Intercept)  1.40342203 1.36756660  1.026218 0.30478864
disp        -0.09517972 0.04800283 -1.982794 0.04739044
hp           0.12170173 0.06777320  1.795721 0.07253897

Upvotes: 1

Related Questions