tidier = function(model, ci = 0.95, digits = 3){
model %>%
broom::tidy(conf.int = TRUE, conf.level = ci) %>%
reframe(
term = term,
estimate = estimate %>% round(digits),
se = statistic %>% round(digits),
statistic = statistic %>% round(digits),
p_value = p.value %>% round(digits),
stars = p.value %>% gtools::stars.pval(),
upper = conf.high %>% round(digits),
lower = conf.low %>% round(digits))
}
def tidier(model, ci = 0.95, digits = 3):
b = model.conf_int(alpha = 1 - ci)
out = pd.DataFrame({
'term': model.params.index,
'estimate': model.params.round(digits),
'se': model.bse.round(digits),
'statistic': model.tvalues.round(digits),
'p_value': model.pvalues.round(digits),
'lower': b[0].round(digits),
'upper': b[1].round(digits)})
out['stars'] = pd.cut(out['p_value'],
[0, .001, .01, .05, .1, 1],
labels = ['***', '**', '*', '.', ''])
return out.reset_index(drop = True)