Rounding with number of digits determined by an equivalence test
Source:R/fmt_factory.R
fmt_equivalence.RdThis function implements the suggestions of Astier & Wolak for the number of decimal digits to keep for coefficient estimates. The other statistics are rounded by fmt_significant().
Arguments
- conf_level
Confidence level to use for the equivalence test (1 - alpha).
- digits
Number of significant digits to keep.
- pdigits
Number of decimal digits to keep for p values. If
NULL, the value ofdigitsis used.- ...
Additional arguments are passed to the
format()function (e.g.,big.marks,scientific). See?format
References
Astier, Nicolas, and Frank A. Wolak. Credible Numbers: A Procedure for Reporting Statistical Precision in Parameter Estimates. No. w32124. National Bureau of Economic Research, 2024.
Examples
library(modelsummary)
mod <- lm(mpg ~ hp, mtcars)
# Default equivalence-based formatting
modelsummary(mod, fmt = fmt_equivalence())
#>
#> +-------------+----------+
#> | | (1) |
#> +=============+==========+
#> | (Intercept) | 30 |
#> +-------------+----------+
#> | | (1.63) |
#> +-------------+----------+
#> | hp | -0.07 |
#> +-------------+----------+
#> | | (0.0101) |
#> +-------------+----------+
#> | Num.Obs. | 32 |
#> +-------------+----------+
#> | R2 | 0.602 |
#> +-------------+----------+
#> | R2 Adj. | 0.589 |
#> +-------------+----------+
#> | AIC | 181.2 |
#> +-------------+----------+
#> | BIC | 185.6 |
#> +-------------+----------+
#> | Log.Lik. | -87.619 |
#> +-------------+----------+
#> | F | 45.460 |
#> +-------------+----------+
#> | RMSE | 3.74 |
#> +-------------+----------+
# alpha = 0.2
modelsummary(mod, fmt = fmt_equivalence(conf_level = .8))
#>
#> +-------------+----------+
#> | | (1) |
#> +=============+==========+
#> | (Intercept) | 30 |
#> +-------------+----------+
#> | | (1.63) |
#> +-------------+----------+
#> | hp | -0.068 |
#> +-------------+----------+
#> | | (0.0101) |
#> +-------------+----------+
#> | Num.Obs. | 32 |
#> +-------------+----------+
#> | R2 | 0.602 |
#> +-------------+----------+
#> | R2 Adj. | 0.589 |
#> +-------------+----------+
#> | AIC | 181.2 |
#> +-------------+----------+
#> | BIC | 185.6 |
#> +-------------+----------+
#> | Log.Lik. | -87.619 |
#> +-------------+----------+
#> | F | 45.460 |
#> +-------------+----------+
#> | RMSE | 3.74 |
#> +-------------+----------+
# default equivalence, but with alternative significant digits for other statistics
modelsummary(mod, fmt = fmt_equivalence(digits = 5))
#>
#> +-------------+------------+
#> | | (1) |
#> +=============+============+
#> | (Intercept) | 30 |
#> +-------------+------------+
#> | | (1.6339) |
#> +-------------+------------+
#> | hp | -0.07 |
#> +-------------+------------+
#> | | (0.010119) |
#> +-------------+------------+
#> | Num.Obs. | 32 |
#> +-------------+------------+
#> | R2 | 0.602 |
#> +-------------+------------+
#> | R2 Adj. | 0.589 |
#> +-------------+------------+
#> | AIC | 181.2 |
#> +-------------+------------+
#> | BIC | 185.6 |
#> +-------------+------------+
#> | Log.Lik. | -87.619 |
#> +-------------+------------+
#> | F | 45.460 |
#> +-------------+------------+
#> | RMSE | 3.74 |
#> +-------------+------------+