3
Is there a package or way to make more visual the output of regressions in R? Something that leaves information more organized, similar to Stata and E-views.
3
Is there a package or way to make more visual the output of regressions in R? Something that leaves information more organized, similar to Stata and E-views.
6
I usually get the output of the regression model I want, turn it into a data frame, and for that I count on the help of the package broom
.
Then I use the table formatting functions such as kable
kableExtra::kableExtra
.
m1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris)
sm1 <- summary(m1)
sm1$coefficients # Eu descobri que é nesse local que fica "guardado" os valores dos coeficientes depois de fazer str(summary(m1))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.2513932 0.3697543 6.088890 9.568102e-09
Sepal.Width 0.8035609 0.1063390 7.556598 4.187340e-12
Speciesversicolor 1.4587431 0.1121079 13.011954 3.478232e-26
Speciesvirginica 1.9468166 0.1000150 19.465255 2.094475e-42
broom
broom::tidy(m1)
# A tibble: 4 x 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 2.25 0.370 6.09 9.57e- 9
2 Sepal.Width 0.804 0.106 7.56 4.19e-12
3 Speciesversicolor 1.46 0.112 13.0 3.48e-26
4 Speciesvirginica 1.95 0.100 19.5 2.09e-42
a <- broom::tidy(m1)
names(a) <- c("Covariáveis", "Estimativa", "Erro Padrão", "Estatística t", "Valor-p")
a
# A tibble: 4 x 5
Covariáveis Estimativa `Erro Padrão` `Estatística t` `Valor-p`
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 2.25 0.370 6.09 9.57e- 9
2 Sepal.Width 0.804 0.106 7.56 4.19e-12
3 Speciesversicolor 1.46 0.112 13.0 3.48e-26
4 Speciesvirginica 1.95 0.100 19.5 2.09e-42
Then just use the function kable
and kable_extra
(where necessary) to report:
And use the extra options of kable
and kableExtra
the will to customize.
When I say "automatic", I mean: A function will collect key model information and printout in a formatted table.
stargazer
The package stargazer
is very good and the most "famous":
library(stargazer)
stargazer(m1, type = "html")
library(sjPlot)
tab_model(m1)
library(jtools)
export_summs(m1)
html
, but with some amendments,pdf
.manual
is that it is limitless, but demand
more time.Browser other questions tagged r rstudio
You are not signed in. Login or sign up in order to post.
It would be possible to put a practical example of how to do this?
– Marcus Nunes
Excellent. This is an answer that should be very well voted on by the OS participants.
– Marcus Nunes
Thank you @Marcus Nunes. Really, when I posted, I thought the examples were missing so the answer is very complete. I hope it helps so!!
– Guilherme Parreira
It will certainly help AP and other users who have similar questions.
– Marcus Nunes
Thank you William, are very good ideas really helped me a lot!!
– Mateus Pereira