From 4cf71de3ac7ad1e3d2ab463569989121ad7fbc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Tue, 7 May 2024 18:48:16 +0200 Subject: [PATCH] fix errors, wordlist, styler, lints --- R/report.compare.loo.R | 54 ++++++++++++++++++++------------------- inst/WORDLIST | 1 + man/report.compare.loo.Rd | 2 ++ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/R/report.compare.loo.R b/R/report.compare.loo.R index b334a4ec..f720b66f 100644 --- a/R/report.compare.loo.R +++ b/R/report.compare.loo.R @@ -59,7 +59,7 @@ report.compare.loo <- function(x, include_IC = TRUE, include_ENP = FALSE, ...) { ic_diff <- -2 * elpd_diff z_elpd_diff <- elpd_diff / se_elpd_diff - p_elpd_diff <- 2 * pnorm(-abs(z_elpd_diff)) + p_elpd_diff <- 2 * stats::pnorm(-abs(z_elpd_diff)) z_ic_diff <- -z_elpd_diff if ("looic" %in% colnames(x)) { @@ -80,45 +80,45 @@ report.compare.loo <- function(x, include_IC = TRUE, include_ENP = FALSE, ...) { # in a parameters.compare.loo() function which would be run here. # Starting text ----- - text <- sprintf( + text1 <- sprintf( paste0( "The difference in predictive accuracy, as indexed by Expected Log ", "Predictive Density (%s), suggests that '%s' is the best model (" ), index_label, modnames[1] ) - if(all(c(include_IC, include_ENP) == FALSE)) { - text <- sprintf(paste0(text, "ELPD = %.2f)"), elpd[1]) - } else { - if(include_IC) { - text <- sprintf(paste0(text, "%s = %.2f"), index_ic, ic[1]) + if (all(c(include_IC, include_ENP))) { + if (include_IC) { + text1 <- sprintf(paste0(text1, "%s = %.2f"), index_ic, ic[1]) } - if(include_ENP) { - if(include_IC) { - text <- sprintf(paste0(text, ", ENP = %.2f)"), enp[1]) + if (include_ENP) { + if (include_IC) { + text1 <- sprintf(paste0(text1, ", ENP = %.2f)"), enp[1]) } else { - text <- sprintf(paste0(text, "ENP = %.2f)"), enp[1]) + text1 <- sprintf(paste0(text1, "ENP = %.2f)"), enp[1]) } } else { - text <- paste0(text, ")") + text1 <- paste0(text1, ")") } + } else { + text1 <- sprintf(paste0(text1, "ELPD = %.2f)"), elpd[1]) } # Other models --- - text_models <- sprintf("'%s' (diff-ELPD = %.2f +- %.2f, %s", - modnames[-1], - elpd_diff[-1], - se_elpd_diff[-1], - insight::format_p(p_elpd_diff[-1])) + text_models <- sprintf( + "'%s' (diff-ELPD = %.2f +- %.2f, %s", + modnames[-1], + elpd_diff[-1], + se_elpd_diff[-1], + insight::format_p(p_elpd_diff[-1]) + ) - if(all(c(include_IC, include_ENP) == FALSE)) { - text_models <- paste0(text_models, ")") - } else { - if(include_IC) { + if (all(c(include_IC, include_ENP))) { + if (include_IC) { text_models <- sprintf(paste0(text_models, ", %s = %.2f"), index_ic, ic[-1]) } - if(include_ENP) { - if(include_IC) { + if (include_ENP) { + if (include_IC) { text_models <- sprintf(paste0(text_models, ", ENP = %.2f)"), enp[-1]) } else { text_models <- sprintf(paste0(text_models, "ENP = %.2f)"), enp[-1]) @@ -126,10 +126,12 @@ report.compare.loo <- function(x, include_IC = TRUE, include_ENP = FALSE, ...) { } else { text_models <- sprintf(paste0(text_models, ")")) } + } else { + text_models <- paste0(text_models, ")") } - text <- paste0(text, ", followed by ", datawizard::text_concatenate( text_models)) - class(text) <- c("report_text", class(text)) - text + text1 <- paste0(text1, ", followed by ", datawizard::text_concatenate(text_models)) + class(text1) <- c("report_text", class(text1)) + text1 } diff --git a/inst/WORDLIST b/inst/WORDLIST index 6f3ef10d..59204c57 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -6,6 +6,7 @@ CMD CSL Dom ELPD +ENP ESS Gabry Hotfix diff --git a/man/report.compare.loo.Rd b/man/report.compare.loo.Rd index 4e5c9729..abb3d4d0 100644 --- a/man/report.compare.loo.Rd +++ b/man/report.compare.loo.Rd @@ -48,6 +48,8 @@ x <- brms::loo_compare( model_names = c("m1", "m2", "m3") ) report(x) +report(x, include_IC = FALSE) +report(x, include_ENP = TRUE) } \dontshow{\}) # examplesIf} }