Question

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.

Était-ce utile?

La solution

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 ...

Autres conseils

It doesn't make sense to save the entire output of a model as a CSV because summary output is not a table. If you want to save the full output you are essentially saving a list (not a table/csv). You can just do:

x<-summary(yourmodel)
save(x, file="modelresults.Rdata")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top