From 8d44cd8e804bb27b704d4eb91cb70be5bad24372 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Aug 2024 20:17:07 +0200 Subject: [PATCH] model_paramaters with exponentiate = TRUE not working with bootstrapped object from bootstrap_model Fixes #1004 --- R/methods_base.R | 8 ++++++-- R/methods_posterior.R | 4 ++++ man/model_parameters.stanreg.Rd | 35 ++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/R/methods_base.R b/R/methods_base.R index 955660264..40afadda8 100644 --- a/R/methods_base.R +++ b/R/methods_base.R @@ -1,9 +1,13 @@ #' @rdname model_parameters.stanreg #' @export -model_parameters.data.frame <- function(model, as_draws = FALSE, verbose = TRUE, ...) { +model_parameters.data.frame <- function(model, + as_draws = FALSE, + exponentiate = FALSE, + verbose = TRUE, + ...) { # treat data frame as bootstraps/posteriors? if (isTRUE(as_draws)) { - return(model_parameters.draws(model, verbose = verbose, ...)) + return(model_parameters.draws(model, exponentiate = exponentiate, verbose = verbose, ...)) } if (isTRUE(verbose)) { insight::format_warning( diff --git a/R/methods_posterior.R b/R/methods_posterior.R index 3b58b59bf..24e096659 100644 --- a/R/methods_posterior.R +++ b/R/methods_posterior.R @@ -8,6 +8,7 @@ model_parameters.draws <- function(model, test = "pd", rope_range = "default", rope_ci = 0.95, + exponentiate = FALSE, keep = NULL, drop = NULL, verbose = TRUE, @@ -33,6 +34,9 @@ model_parameters.draws <- function(model, ... ) + # exponentiate coefficients and SE/CI, if requested + params <- .exponentiate_parameters(params) + attr(params, "ci") <- ci attr(params, "object_name") <- insight::safe_deparse_symbol(substitute(model)) class(params) <- c("parameters_model", "see_parameters_model", class(params)) diff --git a/man/model_parameters.stanreg.Rd b/man/model_parameters.stanreg.Rd index 3980d2292..ef2f3f623 100644 --- a/man/model_parameters.stanreg.Rd +++ b/man/model_parameters.stanreg.Rd @@ -27,7 +27,13 @@ ... ) -\method{model_parameters}{data.frame}(model, as_draws = FALSE, verbose = TRUE, ...) +\method{model_parameters}{data.frame}( + model, + as_draws = FALSE, + exponentiate = FALSE, + verbose = TRUE, + ... +) \method{model_parameters}{brmsfit}( model, @@ -61,6 +67,7 @@ test = "pd", rope_range = "default", rope_ci = 0.95, + exponentiate = FALSE, keep = NULL, drop = NULL, verbose = TRUE, @@ -171,6 +178,19 @@ the data frame is treated as posterior samples and handled similar to Bayesian models. All arguments in \code{...} are passed to \code{model_parameters.draws()}.} +\item{exponentiate}{Logical, indicating whether or not to exponentiate the +coefficients (and related confidence intervals). This is typical for +logistic regression, or more generally speaking, for models with log or +logit links. It is also recommended to use \code{exponentiate = TRUE} for models +with log-transformed response values. \strong{Note:} Delta-method standard +errors are also computed (by multiplying the standard errors by the +transformed coefficients). This is to mimic behaviour of other software +packages, such as Stata, but these standard errors poorly estimate +uncertainty for the transformed coefficient. The transformed confidence +interval more clearly captures this uncertainty. For \code{compare_parameters()}, +\code{exponentiate = "nongaussian"} will only exponentiate coefficients from +non-Gaussian families.} + \item{effects}{Should results for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.} @@ -188,19 +208,6 @@ argument - but no auxiliary parameters). For \code{component = "distributional"} (or \code{"auxiliary"}), components like \code{sigma}, \code{dispersion}, or \code{beta} (and other auxiliary parameters) are returned.} -\item{exponentiate}{Logical, indicating whether or not to exponentiate the -coefficients (and related confidence intervals). This is typical for -logistic regression, or more generally speaking, for models with log or -logit links. It is also recommended to use \code{exponentiate = TRUE} for models -with log-transformed response values. \strong{Note:} Delta-method standard -errors are also computed (by multiplying the standard errors by the -transformed coefficients). This is to mimic behaviour of other software -packages, such as Stata, but these standard errors poorly estimate -uncertainty for the transformed coefficient. The transformed confidence -interval more clearly captures this uncertainty. For \code{compare_parameters()}, -\code{exponentiate = "nongaussian"} will only exponentiate coefficients from -non-Gaussian families.} - \item{standardize}{The method used for standardizing the parameters. Can be \code{NULL} (default; no standardization), \code{"refit"} (for re-fitting the model on standardized data) or one of \code{"basic"}, \code{"posthoc"}, \code{"smart"},