Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing the summary of glm [duplicate]

Tags:

r

printing

I am struggling with saving/printing the glm model summary output. Here is my code;

logmodel=glm(amal~age + LC1 + LC2 + LC3 + LC4, data=random_new, family="binomial")
summary(logmodel)

And output is ;

Call:
glm(formula = amal ~ age + LC1 + LC2 + LC3 + LC4, family = "binomial", 
data = random100_new)

Deviance Residuals: 
    Min        1Q    Median        3Q       Max  
-1.17907  -0.59278  -0.00008  -0.00008   2.37302  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)    
(Intercept) -2.336e-03  1.155e-01  -0.020    0.984    
age          2.633e-05  9.838e-04   0.027    0.979    
LC11        -1.957e+01  4.065e+02  -0.048    0.962    
LC21        -2.752e+00  1.762e-01 -15.617   <2e-16 ***
LC31        -1.957e+01  4.065e+02  -0.048    0.962    
LC41        -1.648e+00  1.275e-01 -12.918   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 2888.7  on 3499  degrees of freedom
Residual deviance: 1907.0  on 3494  degrees of freedom
AIC: 1919

Number of Fisher Scoring iterations: 18

I did try; result=summary.glm(logmodel)$coefficients write.csv(result, file="x.csv")

But it just save the coefficients of the model. Is there any way to save all summary output?

Thanks.

like image 849
user3525533 Avatar asked Nov 02 '25 17:11

user3525533


1 Answers

You could use

sink("outfile.txt")  ## switch standard output to a file
summary(logmodel)
sink()               ## don't forget to turn off redirection
                     ## lots of scope for confusion here!

capture.output may be safer/recommended because you run less risk of forgetting to un-redirect ...

writeLines(capture.output(summary(logmodel)),con="outfile.txt")

Sending the output to a CSV file doesn't really make any sense ...

like image 165
Ben Bolker Avatar answered Nov 05 '25 12:11

Ben Bolker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!