diff --git a/DESCRIPTION b/DESCRIPTION index 826abc7b3..2b7fe815a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.4 +Version: 0.12.4.1 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -160,3 +160,4 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: easystats/insight diff --git a/R/performance_aicc.R b/R/performance_aicc.R index bc1f3e0ab..eb10bc40f 100644 --- a/R/performance_aicc.R +++ b/R/performance_aicc.R @@ -266,8 +266,6 @@ performance_aicc.rma <- function(x, ...) { } - - # jacobian / derivate for log models and other transformations ---------------- @@ -275,68 +273,13 @@ performance_aicc.rma <- function(x, ...) { .adjust_ic_jacobian <- function(model, ic) { response_transform <- insight::find_transformation(model) if (!is.null(ic) && !is.null(response_transform) && !identical(response_transform, "identity")) { - adjustment <- .safe(.ll_analytic_adjustment(model, insight::get_weights(model, remove_na = TRUE))) + adjustment <- .safe(insight::get_loglikelihood_adjustment( + model, + insight::get_weights(model, remove_na = TRUE) + )) if (!is.null(adjustment)) { ic <- ic - 2 * adjustment } } ic } - - -# copied from `insight` -.ll_analytic_adjustment <- function(x, model_weights = NULL) { - tryCatch( - { - trans <- insight::find_transformation(x) - switch(trans, - identity = .weighted_sum(log(insight::get_response(x)), w = model_weights), - log = .weighted_sum(log(1 / insight::get_response(x)), w = model_weights), - log1p = .weighted_sum(log(1 / (insight::get_response(x) + 1)), w = model_weights), - log2 = .weighted_sum(log(1 / (insight::get_response(x) * log(2))), w = model_weights), - log10 = .weighted_sum(log(1 / (insight::get_response(x) * log(10))), w = model_weights), - exp = .weighted_sum(insight::get_response(x), w = model_weights), - expm1 = .weighted_sum((insight::get_response(x) - 1), w = model_weights), - sqrt = .weighted_sum(log(0.5 / sqrt(insight::get_response(x))), w = model_weights), - .ll_jacobian_adjustment(x, model_weights) - ) - }, - error = function(e) { - NULL - } - ) -} - - -# this function calculates the adjustment for the log-likelihood of a model -# with transformed response -.ll_jacobian_adjustment <- function(model, weights = NULL) { - tryCatch( - { - trans <- insight::get_transformation(model)$transformation - .weighted_sum(log( - diag(attr(with( - insight::get_data(model, verbose = FALSE), - stats::numericDeriv( - expr = quote(trans( - get(insight::find_response(model)) - )), - theta = insight::find_response(model) - ) - ), "gradient")) - ), weights) - }, - error = function(e) { - NULL - } - ) -} - - -.weighted_sum <- function(x, w = NULL, ...) { - if (is.null(w)) { - mean(x) * length(x) - } else { - stats::weighted.mean(x, w) * length(x) - } -}