I want to insert the results it returns summary(glm(*))
into a table so that I can present the results in a way that is more visually appealing.
Let be the following dataframe:
SAP niv_est edad sexo
1 1 1 84 0
2 0 4 26 1
3 1 4 56 0
4 0 2 70 1
5 0 3 61 1
6 0 4 35 0
We want to perform a binomial logit model and have it show us the results, so:
summary(glm(SAP ~ niv_est + edad + sexo,data = datos_duda, family = binomial(link = "logit")))
This returns the following:
Call:
glm(formula = SAP ~ niv_est + edad + sexo, family = binomial(link = "logit"),
data = datos_duda, na.action = "na.omit")
Deviance Residuals:
1 2 3 4 5 6
5.662e-06 -2.110e-08 7.055e-06 -4.995e-06 -6.821e-06 -8.383e-06
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -190.502 748512.185 0 1
niv_est 21.404 112623.998 0 1
edad 2.309 7487.683 0 1
sexo -39.042 130544.837 0 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 7.6382e+00 on 5 degrees of freedom
Residual deviance: 2.2359e-10 on 2 degrees of freedom
AIC: 8
Number of Fisher Scoring iterations: 24
Ignoring the results of the estimation, what I want is for it to return the results generated in the table Coefficients
in a more attractive way and visually, since I have to present these results for my TFG . I've tried inserting this code into an R markdown file using the library printr
but this returns the same table as if I didn't run library(printr
. Is there an alternative to not having to pass the data to a table manually using excel, for example?
To generate an array similar to the data of
Coefficients
we could simply do something like this:That is, we instantiate an object of the class
summary.glm
and extract from it the matrix corresponding to the coefficients. This is the simplest, we could eventually regenerate the table directly from the model (there is enough data to do it), but it would force us to "reverse engineer" it to reproduce what it doessummary()
. Finally, I can suggest the packagebroom
that is very useful for working with models and integrating them with the universetidyverse
:There is a package called
stargazer
which converts the output of tables and regression models in latex, txt, word and html format. It is a presentational approach used in papers.You will have in your working directory a word file with the regression in a very stylish way.
I hope I can serve you.
You can place multiple models in the function
stargazer
.