tidy_estimates() turns the output of a model (or an existing data frame of
results) into a single standardised table with the columns term,
estimate, std.error, conf.low and conf.high. It is the common
currency used by coefficient_plot() and compare_models(), but is useful
on its own.
Arguments
- x
A fitted model or a data frame of results.
- conf_level
Confidence (or credible) level for the interval.
- ...
Passed to methods (and to
broom::tidy()in the fallback). ThemerModmethod additionally acceptseffects, which currently only supports"fixed".
Value
A data frame with one row per term and the columns term,
estimate, std.error, conf.low and conf.high.
Details
Methods are provided for lm, glm and merMod (mixed models fitted with
'lme4') objects, and for data frames. For any other model class the function
falls back to broom::tidy() when the 'broom' package is installed.
Confidence intervals are computed with the normal approximation
(estimate +/- z * standard error) for glm and merMod objects, which is
fast and dependency-free; lm objects use the exact t-based interval. Supply
a data frame with your own intervals (for example profiled or posterior
intervals) to override this.
Examples
fit <- lm(yield ~ rainfall + fertiliser + treatment, data = crop_yield)
tidy_estimates(fit)
#> term estimate std.error conf.low conf.high
#> 1 (Intercept) -0.764921362 0.3933784207 -1.540719161 0.010876437
#> 2 rainfall 0.004527229 0.0007284476 0.003090628 0.005963831
#> 3 fertiliser 0.010488592 0.0013233496 0.007878760 0.013098424
#> 4 treatmentenhanced 1.290135752 0.1189761405 1.055498001 1.524773503
# A data frame of pre-computed estimates is standardised, not re-fitted:
df <- data.frame(
parameter = c("a", "b"),
Estimate = c(0.2, -0.4),
"2.5 %" = c(0.1, -0.6),
"97.5 %" = c(0.3, -0.2),
check.names = FALSE
)
tidy_estimates(df)
#> term estimate std.error conf.low conf.high
#> 1 a 0.2 NA 0.1 0.3
#> 2 b -0.4 NA -0.6 -0.2
