Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Summary.glm to CSV file?

Tags:

r

I am struggling with printing results from "summary.glm" to a CSV file. My code, which is rather simple, is as follows:

results <-glm(dv ~ iv + iv2, family=binomial, data=dataframe)
results_df <-summary.glm(results)
write.csv(results_df, "myCSV.csv")

This yields the error: cannot coerce class 'summary.glm' into a data.frame'.

All that I really need to do is export my coefficients, as odds ratios, into a CSV file that also includes standard errors and p-values. I'm sure there is a package to do this; I just haven't found it. Please help!

like image 422
roody Avatar asked Jun 22 '26 03:06

roody


1 Answers

Just do:

results_df <-summary.glm(results)$coefficients

This extracts the coefficients data frame.

like image 131
David Robinson Avatar answered Jun 23 '26 19:06

David Robinson



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!