Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add stars to broom package's tidy() function output?

I have been using the broom package's tidy() function in R to print my model summaries.

However, the tidy() function returns p-values without stars, which makes it a bit weird for many people who are used to seeing stars in model summaries.

Does anyone know a way to add stars to the output?

like image 319
bcdeniz Avatar asked Feb 20 '18 03:02

bcdeniz


1 Answers

We can use a convenient function stars.pval from gtools to do this

library(gtools)
library(broom)
library(dplyr)
data(mtcars)
mtcars %>%
   lm(mpg ~ wt + qsec, .) %>%
   tidy %>%
   mutate(signif = stars.pval(p.value))
#        term  estimate std.error  statistic      p.value signif
#1 (Intercept) 19.746223 5.2520617   3.759709 7.650466e-04    ***
#2          wt -5.047982 0.4839974 -10.429771 2.518948e-11    ***
#3        qsec  0.929198 0.2650173   3.506179 1.499883e-03     **
like image 128
akrun Avatar answered Oct 03 '22 07:10

akrun