From aa555c310b323347daaa8cd03b73800de184125a Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 11 Jul 2024 11:11:33 +0200 Subject: [PATCH] Confidence intervals for ICC, it seems that none of the `ci_method`s work (neither default, `boot` or `analytical`). Fixes #745 --- R/helpers.R | 2 +- R/icc.R | 12 ++++++++++-- R/r2_nakagawa.R | 12 ++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index c231d6226..2276c21c1 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -1,6 +1,6 @@ # small wrapper around this commonly used try-catch .safe <- function(code, on_error = NULL) { - if (getOption("easystats_erros", FALSE) && is.null(on_error)) { + if (isTRUE(getOption("easystats_erros", FALSE) && is.null(on_error))) { code } else { tryCatch(code, error = function(e) on_error) diff --git a/R/icc.R b/R/icc.R index 52117bc4a..2f84437ef 100644 --- a/R/icc.R +++ b/R/icc.R @@ -591,7 +591,11 @@ print.icc_decomposed <- function(x, digits = 2, ...) { .boot_icc_fun <- function(data, indices, model, tolerance) { d <- data[indices, ] # allows boot to select sample fit <- suppressWarnings(suppressMessages(stats::update(model, data = d))) - vars <- .compute_random_vars(fit, tolerance, verbose = FALSE) + vars <- .compute_random_vars( + fit, + tolerance, + verbose = isTRUE(getOption("easystats_erros", FALSE)) + ) if (is.null(vars) || all(is.na(vars))) { return(c(NA, NA)) } @@ -604,7 +608,11 @@ print.icc_decomposed <- function(x, digits = 2, ...) { # bootstrapping using "lme4::bootMer" .boot_icc_fun_lme4 <- function(model) { - vars <- .compute_random_vars(model, tolerance = 1e-05, verbose = FALSE) + vars <- .compute_random_vars( + model, + tolerance = 1e-10, + verbose = isTRUE(getOption("easystats_erros", FALSE)) + ) if (is.null(vars) || all(is.na(vars))) { return(c(NA, NA)) } diff --git a/R/r2_nakagawa.R b/R/r2_nakagawa.R index 59d4d1906..366db32ec 100644 --- a/R/r2_nakagawa.R +++ b/R/r2_nakagawa.R @@ -281,7 +281,11 @@ print.r2_nakagawa <- function(x, digits = 3, ...) { .boot_r2_fun <- function(data, indices, model, tolerance) { d <- data[indices, ] # allows boot to select sample fit <- suppressWarnings(suppressMessages(stats::update(model, data = d))) - vars <- .compute_random_vars(fit, tolerance, verbose = FALSE) + vars <- .compute_random_vars( + fit, + tolerance, + verbose = isTRUE(getOption("easystats_erros", FALSE)) + ) if (is.null(vars) || all(is.na(vars))) { return(c(NA, NA)) } @@ -298,7 +302,11 @@ print.r2_nakagawa <- function(x, digits = 3, ...) { # bootstrapping using "lme4::bootMer" .boot_r2_fun_lme4 <- function(model) { - vars <- .compute_random_vars(model, tolerance = 1e-05, verbose = FALSE) + vars <- .compute_random_vars( + model, + tolerance = 1e-10, + verbose = isTRUE(getOption("easystats_erros", FALSE)) + ) if (is.null(vars) || all(is.na(vars))) { return(c(NA, NA)) }