Load Function
# Let's write a little tidier function..
tidier = function(model, ci = 0.95, digits = 3){
model %>% # for a model object
# get data.frame of coefficients
# ask for a confidence interval matching the 'ci' above!
broom::tidy(conf.int = TRUE, conf.level = ci) %>%
# And round and relabel them
reframe(
term = term,
# Round numbers to a certain number of 'digits'
estimate = estimate %>% round(digits),
se = statistic %>% round(digits),
statistic = statistic %>% round(digits),
p_value = p.value %>% round(digits),
# Get stars to show statistical significance
stars = p.value %>% gtools::stars.pval(),
# Get better names
upper = conf.high %>% round(digits),
lower = conf.low %>% round(digits))
}
# The same little tidier function..
# broom::tidy -> .params and .conf_int()
def tidier(model, ci = 0.95, digits = 3):
# confidence interval matching the 'ci' above
b = model.conf_int(alpha = 1 - ci)
out = pd.DataFrame({
'term': model.params.index,
# Round numbers to 'digits' places
'estimate': model.params.round(digits),
'se': model.bse.round(digits),
'statistic': model.tvalues.round(digits),
'p_value': model.pvalues.round(digits),
# Get better names
'lower': b[0].round(digits),
'upper': b[1].round(digits)})
# Stars to show statistical significance
out['stars'] = pd.cut(out['p_value'],
[0, .001, .01, .05, .1, 1],
labels = ['***', '**', '*', '.', ''])
return out.reset_index(drop = True)