From 59f3ee8e0a16fef0a9011bb1c7cb154c56e430d3 Mon Sep 17 00:00:00 2001 From: Dominique Makowski Date: Thu, 28 Mar 2024 13:31:47 +0000 Subject: [PATCH 01/10] add --- DESCRIPTION | 1 + NAMESPACE | 2 ++ R/report.BFBayesFactor.R | 62 +++++++++++++++++++++++++++++++++++++ man/report.BFBayesFactor.Rd | 33 ++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 R/report.BFBayesFactor.R create mode 100644 man/report.BFBayesFactor.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 35d6c831..14f8b825 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -95,6 +95,7 @@ Collate: 'format_model.R' 'reexports.R' 'report-package.R' + 'report.BFBayesFactor.R' 'utils_combine_tables.R' 'report.lm.R' 'report.MixMod.R' diff --git a/NAMESPACE b/NAMESPACE index a3cb2ff5..45ea68b4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,7 @@ S3method(print,report_table) S3method(print,report_text) S3method(print_html,report_sample) S3method(print_md,report_sample) +S3method(report,BFBayesFactor) S3method(report,Date) S3method(report,MixMod) S3method(report,anova) @@ -166,6 +167,7 @@ S3method(report_random,glmmTMB) S3method(report_random,lme) S3method(report_random,merMod) S3method(report_random,stanreg) +S3method(report_statistics,BFBayesFactor) S3method(report_statistics,Date) S3method(report_statistics,MixMod) S3method(report_statistics,anova) diff --git a/R/report.BFBayesFactor.R b/R/report.BFBayesFactor.R new file mode 100644 index 00000000..38a0f28f --- /dev/null +++ b/R/report.BFBayesFactor.R @@ -0,0 +1,62 @@ +#' Reporting `BFBayesFactor` objects from the `BayesFactor` package +#' +#' Interpretation of the Bayes factor output from the `BayesFactor` package. +#' +#' @param x An object of class `BFBayesFactor`. +#' @param h0,h1 Names of the null and alternative hypotheses. +#' +#' @examplesIf requireNamespace("BayesFactor", quietly = TRUE) +#' \donttest{ +#' library(BayesFactor) +#' +#' rez <- BayesFactor::ttestBF(iris$Sepal.Width, iris$Sepal.Length) +#' report_statistics(rez) +#' report(rez, h0="the null hypothesis", h1="the alternative") +#' +#' rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) +#' report(rez) +#' } +#' +#' @export +report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { + param <- parameters::parameters(x, ...) + bf <- param$BF + dir <- ifelse(bf < 1, "h0", "h1") + + + if (dir == "h1") { + text <- paste0("There is ", + effectsize::interpret_bf(bf, ...), + " ", + h1, + " over ", + h0, + " (", report_statistics(x), ").") + } else { + text <- paste0("There is ", + effectsize::interpret_bf(1/bf, ...), + " ", + h0, + " over ", + h1, + " (", report_statistics(x), ").") + } + text +} + + + +#' @rdname report.BFBayesFactor +#' @export +report_statistics.BFBayesFactor <- function(x, table = NULL, ...) { + if(is.null(table)) { + table <- parameters::parameters(x, ...) + } + + bf <- table$BF + text <- ifelse(bf < 1, + insight::format_bf(1/bf, name="BF01"), + insight::format_bf(bf, name="BF10")) + text +} + diff --git a/man/report.BFBayesFactor.Rd b/man/report.BFBayesFactor.Rd new file mode 100644 index 00000000..b75e2e59 --- /dev/null +++ b/man/report.BFBayesFactor.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/report.BFBayesFactor.R +\name{report.BFBayesFactor} +\alias{report.BFBayesFactor} +\alias{report_statistics.BFBayesFactor} +\title{Reporting \code{BFBayesFactor} objects from the \code{BayesFactor} package} +\usage{ +\method{report}{BFBayesFactor}(x, h0 = "H0", h1 = "H1", ...) + +\method{report_statistics}{BFBayesFactor}(x, table = NULL, ...) +} +\arguments{ +\item{x}{An object of class \code{BFBayesFactor}.} + +\item{h0, h1}{Names of the null and alternative hypotheses.} +} +\description{ +Interpretation of the Bayes factor output from the \code{BayesFactor} package. +} +\examples{ +\dontshow{if (requireNamespace("BayesFactor", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\donttest{ +library(BayesFactor) + +rez <- BayesFactor::ttestBF(iris$Sepal.Width, iris$Sepal.Length) +report_statistics(rez) +report(rez, h0="the null hypothesis", h1="the alternative") + +rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) +report(rez) +} +\dontshow{\}) # examplesIf} +} From 46dfa7be6736c6cc7a752b7fba0deb8efaada3f2 Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Thu, 28 Mar 2024 16:59:15 +0200 Subject: [PATCH 02/10] Update report.BFBayesFactor.R --- R/report.BFBayesFactor.R | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/R/report.BFBayesFactor.R b/R/report.BFBayesFactor.R index 38a0f28f..bec5f7f1 100644 --- a/R/report.BFBayesFactor.R +++ b/R/report.BFBayesFactor.R @@ -19,7 +19,17 @@ #' #' @export report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { - param <- parameters::parameters(x, ...) + if ("BFlinearModel" %in% class(x@numerator[[1]])) { + return(report(bayestestR::bayesfactor_models(x), ...)) + } + + if (length(x@numerator) > 1) { + insight::format_alert("Multiple `BFBayesFactor` models detected - reporting for the first numerator model.", + "See help(\"get_parameters\", package = \"insight\").") + x <- x[1] + } + + param <- parameters::parameters(x[1], ...) bf <- param$BF dir <- ifelse(bf < 1, "h0", "h1") @@ -31,7 +41,7 @@ report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { h1, " over ", h0, - " (", report_statistics(x), ").") + " (", report_statistics(x, ...), ").") } else { text <- paste0("There is ", effectsize::interpret_bf(1/bf, ...), @@ -39,7 +49,7 @@ report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { h0, " over ", h1, - " (", report_statistics(x), ").") + " (", report_statistics(x, ...), ").") } text } @@ -50,13 +60,18 @@ report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { #' @export report_statistics.BFBayesFactor <- function(x, table = NULL, ...) { if(is.null(table)) { + if (length(x@numerator) > 1) { + insight::format_alert("Multiple `BFBayesFactor` models detected - reporting for the first numerator model.", + "See help(\"get_parameters\", package = \"insight\").") + x <- x[1] + } table <- parameters::parameters(x, ...) } bf <- table$BF text <- ifelse(bf < 1, - insight::format_bf(1/bf, name="BF01"), - insight::format_bf(bf, name="BF10")) + insight::format_bf(1/bf, name="BF01", ...), + insight::format_bf(bf, name="BF10", ...)) text } From b0212217c5fd330a33532e187a8e50e2d2fee9cb Mon Sep 17 00:00:00 2001 From: Dominique Makowski Date: Thu, 28 Mar 2024 16:18:46 +0000 Subject: [PATCH 03/10] exact=TRUE --- R/report.BFBayesFactor.R | 2 +- man/report.BFBayesFactor.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/report.BFBayesFactor.R b/R/report.BFBayesFactor.R index bec5f7f1..bc4220c8 100644 --- a/R/report.BFBayesFactor.R +++ b/R/report.BFBayesFactor.R @@ -10,7 +10,7 @@ #' library(BayesFactor) #' #' rez <- BayesFactor::ttestBF(iris$Sepal.Width, iris$Sepal.Length) -#' report_statistics(rez) +#' report_statistics(rez, exact=TRUE) # Print exact BF #' report(rez, h0="the null hypothesis", h1="the alternative") #' #' rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) diff --git a/man/report.BFBayesFactor.Rd b/man/report.BFBayesFactor.Rd index b75e2e59..f62460df 100644 --- a/man/report.BFBayesFactor.Rd +++ b/man/report.BFBayesFactor.Rd @@ -23,7 +23,7 @@ Interpretation of the Bayes factor output from the \code{BayesFactor} package. library(BayesFactor) rez <- BayesFactor::ttestBF(iris$Sepal.Width, iris$Sepal.Length) -report_statistics(rez) +report_statistics(rez, exact=TRUE) # Print exact BF report(rez, h0="the null hypothesis", h1="the alternative") rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) From ef0292eb39518ab6acb43d8df544fcb1e39f4fc3 Mon Sep 17 00:00:00 2001 From: Dominique Makowski Date: Fri, 29 Mar 2024 09:45:34 +0000 Subject: [PATCH 04/10] docs --- R/report.BFBayesFactor.R | 2 ++ man/report.BFBayesFactor.Rd | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/R/report.BFBayesFactor.R b/R/report.BFBayesFactor.R index bc4220c8..8d040773 100644 --- a/R/report.BFBayesFactor.R +++ b/R/report.BFBayesFactor.R @@ -4,6 +4,8 @@ #' #' @param x An object of class `BFBayesFactor`. #' @param h0,h1 Names of the null and alternative hypotheses. +#' @param table A `parameters` table (this argument is meant for internal use). +#' @param ... Other arguments to be passed to [effectsize::interpret_bf] and [insight::format_bf]. #' #' @examplesIf requireNamespace("BayesFactor", quietly = TRUE) #' \donttest{ diff --git a/man/report.BFBayesFactor.Rd b/man/report.BFBayesFactor.Rd index f62460df..31261d76 100644 --- a/man/report.BFBayesFactor.Rd +++ b/man/report.BFBayesFactor.Rd @@ -13,6 +13,10 @@ \item{x}{An object of class \code{BFBayesFactor}.} \item{h0, h1}{Names of the null and alternative hypotheses.} + +\item{...}{Other arguments to be passed to \link[effectsize:interpret_bf]{effectsize::interpret_bf} and \link[insight:format_bf]{insight::format_bf}.} + +\item{table}{A \code{parameters} table (this argument is meant for internal use).} } \description{ Interpretation of the Bayes factor output from the \code{BayesFactor} package. From ec1d9c084247fb1cba2a76e66b8bc2a577cf2c7f Mon Sep 17 00:00:00 2001 From: Dominique Makowski Date: Fri, 29 Mar 2024 09:47:40 +0000 Subject: [PATCH 05/10] Update DESCRIPTION --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 14f8b825..dda6573d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -65,6 +65,7 @@ Imports: tools, utils Suggests: + BayesFactor, brms, ivreg, knitr, From d21553c7685940acbc67c1d6e6615d851afdce3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:27:37 +0200 Subject: [PATCH 06/10] fix lints, build_reference_index --- R/report.BFBayesFactor.R | 70 ++++++++++++++++++++++------------------ _pkgdown.yml | 1 + 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/R/report.BFBayesFactor.R b/R/report.BFBayesFactor.R index 8d040773..b6f597c9 100644 --- a/R/report.BFBayesFactor.R +++ b/R/report.BFBayesFactor.R @@ -12,48 +12,54 @@ #' library(BayesFactor) #' #' rez <- BayesFactor::ttestBF(iris$Sepal.Width, iris$Sepal.Length) -#' report_statistics(rez, exact=TRUE) # Print exact BF -#' report(rez, h0="the null hypothesis", h1="the alternative") +#' report_statistics(rez, exact = TRUE) # Print exact BF +#' report(rez, h0 = "the null hypothesis", h1 = "the alternative") #' #' rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) #' report(rez) #' } #' #' @export -report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { - if ("BFlinearModel" %in% class(x@numerator[[1]])) { +report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) { + if (inherits("BFlinearModel", class(x@numerator[[1]]))) { return(report(bayestestR::bayesfactor_models(x), ...)) } if (length(x@numerator) > 1) { - insight::format_alert("Multiple `BFBayesFactor` models detected - reporting for the first numerator model.", - "See help(\"get_parameters\", package = \"insight\").") + insight::format_alert( + "Multiple `BFBayesFactor` models detected - reporting for the first numerator model.", + "See help(\"get_parameters\", package = \"insight\")." + ) x <- x[1] } param <- parameters::parameters(x[1], ...) bf <- param$BF - dir <- ifelse(bf < 1, "h0", "h1") + other_dir <- ifelse(bf < 1, "h0", "h1") - if (dir == "h1") { - text <- paste0("There is ", - effectsize::interpret_bf(bf, ...), - " ", - h1, - " over ", - h0, - " (", report_statistics(x, ...), ").") + if (other_dir == "h1") { + other_text <- paste0( + "There is ", + effectsize::interpret_bf(bf, ...), + " ", + h1, + " over ", + h0, + " (", report_statistics(x, ...), ")." + ) } else { - text <- paste0("There is ", - effectsize::interpret_bf(1/bf, ...), - " ", - h0, - " over ", - h1, - " (", report_statistics(x, ...), ").") + other_text <- paste0( + "There is ", + effectsize::interpret_bf(1 / bf, ...), + " ", + h0, + " over ", + h1, + " (", report_statistics(x, ...), ")." + ) } - text + other_text } @@ -61,19 +67,21 @@ report.BFBayesFactor <- function(x, h0="H0", h1="H1", ...) { #' @rdname report.BFBayesFactor #' @export report_statistics.BFBayesFactor <- function(x, table = NULL, ...) { - if(is.null(table)) { + if (is.null(table)) { if (length(x@numerator) > 1) { - insight::format_alert("Multiple `BFBayesFactor` models detected - reporting for the first numerator model.", - "See help(\"get_parameters\", package = \"insight\").") + insight::format_alert( + "Multiple `BFBayesFactor` models detected - reporting for the first numerator model.", + "See help(\"get_parameters\", package = \"insight\")." + ) x <- x[1] } table <- parameters::parameters(x, ...) } bf <- table$BF - text <- ifelse(bf < 1, - insight::format_bf(1/bf, name="BF01", ...), - insight::format_bf(bf, name="BF10", ...)) - text + other_text <- ifelse(bf < 1, + insight::format_bf(1 / bf, name = "BF01", ...), + insight::format_bf(bf, name = "BF10", ...) + ) + other_text } - diff --git a/_pkgdown.yml b/_pkgdown.yml index e8dc6725..7584f212 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -91,6 +91,7 @@ reference: - report.stanreg - report.test_performance - report.estimate_contrasts + - report.BFBayesFactor - title: Report Non-Statistical Objects desc: | From 92bbfc8cfabcd280327e4c59e03853c68abc288d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:36:33 +0200 Subject: [PATCH 07/10] NEWS, pkgdown --- NEWS.md | 1 + _pkgdown.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 00b229cb..07728045 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ Minor changes * `report` now supports reporting of Bayesian model comparison with variables of class `brms::loo_compare`. +* `report` now supports reporting of BayesFactor objects with variables of class `BFBayesFactor`. # report 0.5.8 diff --git a/_pkgdown.yml b/_pkgdown.yml index adc8b7bf..ee0b4da7 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -91,8 +91,8 @@ reference: - report.stanreg - report.test_performance - report.estimate_contrasts - - report.BFBayesFactor - report.compare.loo + - report.BFBayesFactor - title: Report Non-Statistical Objects desc: | From b17dbd861e5fe245acffa24ae63346eb381369c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:05:50 +0200 Subject: [PATCH 08/10] update snapshots, document --- man/report.BFBayesFactor.Rd | 4 +-- .../testthat/_snaps/windows/report.brmsfit.md | 35 ------------------- .../_snaps/windows/report_performance.md | 24 ------------- 3 files changed, 2 insertions(+), 61 deletions(-) diff --git a/man/report.BFBayesFactor.Rd b/man/report.BFBayesFactor.Rd index 31261d76..871c7ece 100644 --- a/man/report.BFBayesFactor.Rd +++ b/man/report.BFBayesFactor.Rd @@ -27,8 +27,8 @@ Interpretation of the Bayes factor output from the \code{BayesFactor} package. library(BayesFactor) rez <- BayesFactor::ttestBF(iris$Sepal.Width, iris$Sepal.Length) -report_statistics(rez, exact=TRUE) # Print exact BF -report(rez, h0="the null hypothesis", h1="the alternative") +report_statistics(rez, exact = TRUE) # Print exact BF +report(rez, h0 = "the null hypothesis", h1 = "the alternative") rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) report(rez) diff --git a/tests/testthat/_snaps/windows/report.brmsfit.md b/tests/testthat/_snaps/windows/report.brmsfit.md index 4f8894dd..35e5ea49 100644 --- a/tests/testthat/_snaps/windows/report.brmsfit.md +++ b/tests/testthat/_snaps/windows/report.brmsfit.md @@ -4,41 +4,6 @@ report(model, verbose = FALSE) Message Start sampling - Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 1 Exception: normal_id_glm_lpdf: Scale vector is 0, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 1 - Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 2 - Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 2 - Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 3 - Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 3 - Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 3 - Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: - Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in 'C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/model-12d437f47a61.stan', line 35, column 4 to column 62) - Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, - Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. - Chain 3 Output We fitted a Bayesian linear model (estimated using MCMC sampling with 4 chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt diff --git a/tests/testthat/_snaps/windows/report_performance.md b/tests/testthat/_snaps/windows/report_performance.md index 0e669f03..76bd46c4 100644 --- a/tests/testthat/_snaps/windows/report_performance.md +++ b/tests/testthat/_snaps/windows/report_performance.md @@ -2,10 +2,6 @@ Code report_performance(x5) - Message - VSCode WebView has restricted access to local file. - Opening in external browser... - Browsing file:///C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/file12d47a7090f_StanProgress.html Output The model's explanatory power is substantial (R2 = 0.62, 95% CI [0.53, 0.69], adj. R2 = 0.61) @@ -14,10 +10,6 @@ Code summary(report_performance(x5)) - Message - VSCode WebView has restricted access to local file. - Opening in external browser... - Browsing file:///C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/file12d465985229_StanProgress.html Output [1] "The model's explanatory power is substantial (R2 = 0.62, adj. R2 = 0.61)" @@ -25,10 +17,6 @@ Code report_performance(x6) - Message - VSCode WebView has restricted access to local file. - Opening in external browser... - Browsing file:///C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/file12d4560a39d2_StanProgress.html Output The model's explanatory power is substantial (R2 = 0.54, 95% CI [0.27, 0.77]) @@ -36,10 +24,6 @@ Code summary(report_performance(x6)) - Message - VSCode WebView has restricted access to local file. - Opening in external browser... - Browsing file:///C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/file12d452f95d46_StanProgress.html Output [1] "The model's explanatory power is substantial (R2 = 0.54)" @@ -47,10 +31,6 @@ Code report_performance(x7) - Message - VSCode WebView has restricted access to local file. - Opening in external browser... - Browsing file:///C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/file12d412fbc1_StanProgress.html Output The model's explanatory power is substantial (R2 = 0.83, 95% CI [0.79, 0.86], adj. R2 = 0.83) and the part related to the fixed effects alone (marginal R2) @@ -60,10 +40,6 @@ Code summary(report_performance(x7)) - Message - VSCode WebView has restricted access to local file. - Opening in external browser... - Browsing file:///C:/Users/DL/AppData/Local/Temp/RtmpERRA9z/file12d426713848_StanProgress.html Output [1] "The model's explanatory power is substantial (R2 = 0.83, adj. R2 = 0.83) and the part related to the fixed effects alone (marginal R2) is of 0.95" From 23a796dd217675b85c61a186c0e0f00f29ae46c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:45:34 +0200 Subject: [PATCH 09/10] skip test, update wordlist --- inst/WORDLIST | 2 +- tests/testthat/_snaps/windows/report_performance.md | 9 --------- tests/testthat/test-report_performance.R | 5 +++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/inst/WORDLIST b/inst/WORDLIST index af7640ca..6f3ef10d 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,5 +1,6 @@ APA Args +BayesFactor BibLaTeX CMD CSL @@ -30,7 +31,6 @@ easystats elpd github htest -https ivreg lifecycle mattansb diff --git a/tests/testthat/_snaps/windows/report_performance.md b/tests/testthat/_snaps/windows/report_performance.md index 76bd46c4..1e67eb70 100644 --- a/tests/testthat/_snaps/windows/report_performance.md +++ b/tests/testthat/_snaps/windows/report_performance.md @@ -29,15 +29,6 @@ # report_performance Bayesian 2) - Code - report_performance(x7) - Output - The model's explanatory power is substantial (R2 = 0.83, 95% CI [0.79, 0.86], - adj. R2 = 0.83) and the part related to the fixed effects alone (marginal R2) - is of 0.95 (95% CI [0.93, 0.97]) - ---- - Code summary(report_performance(x7)) Output diff --git a/tests/testthat/test-report_performance.R b/tests/testthat/test-report_performance.R index 76a62b3f..4e842c32 100644 --- a/tests/testthat/test-report_performance.R +++ b/tests/testthat/test-report_performance.R @@ -119,10 +119,11 @@ test_that("report_performance Bayesian 2)", { ) expect_snapshot( variant = "windows", - report_performance(x7) + summary(report_performance(x7)) ) + skip("Skipping because of a .1 decimal difference in snapshots") expect_snapshot( variant = "windows", - summary(report_performance(x7)) + report_performance(x7) ) }) From dbfce62bf4488103047623e5517a314c9254a08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:39:27 +0200 Subject: [PATCH 10/10] delete problematic report.brms snapshot --- .../testthat/_snaps/windows/report.brmsfit.md | 124 ------------------ tests/testthat/test-report.brmsfit.R | 7 +- tests/testthat/test-report.lm.R | 2 +- tests/testthat/test-report_performance.R | 2 +- 4 files changed, 6 insertions(+), 129 deletions(-) delete mode 100644 tests/testthat/_snaps/windows/report.brmsfit.md diff --git a/tests/testthat/_snaps/windows/report.brmsfit.md b/tests/testthat/_snaps/windows/report.brmsfit.md deleted file mode 100644 index 35e5ea49..00000000 --- a/tests/testthat/_snaps/windows/report.brmsfit.md +++ /dev/null @@ -1,124 +0,0 @@ -# report.brms - - Code - report(model, verbose = FALSE) - Message - Start sampling - Output - We fitted a Bayesian linear model (estimated using MCMC sampling with 4 chains - of 300 iterations and a warmup of 150) to predict mpg with qsec and wt - (formula: mpg ~ qsec + wt). Priors over parameters were set as student_t - (location = 19.20, scale = 5.40) distributions. The model's explanatory power - is substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this - model: - - - The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67% - probability of being positive (> 0), 99.67% of being significant (> 0.30), and - 99.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 343) - - The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00% - probability of being positive (> 0), 99.17% of being significant (> 0.30), and - 0.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 345) - - The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00% - probability of being negative (< 0), 100.00% of being significant (< -0.30), - and 100.00% of being large (< -1.81). The estimation successfully converged - (Rhat = 0.999) but the indices are unreliable (ESS = 586) - - Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT) - framework, we report the median of the posterior distribution and its 95% CI - (Highest Density Interval), along the probability of direction (pd), the - probability of significance and the probability of being large. The thresholds - beyond which the effect is considered as significant (i.e., non-negligible) and - large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the - outcome's SD). Convergence and stability of the Bayesian sampling has been - assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and - Effective Sample Size (ESS), which should be greater than 1000 (Burkner, - 2017)., We fitted a Bayesian linear model (estimated using MCMC sampling with 4 - chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt - (formula: mpg ~ qsec + wt). Priors over parameters were set as uniform - (location = , scale = ) distributions. The model's explanatory power is - substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this - model: - - - The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67% - probability of being positive (> 0), 99.67% of being significant (> 0.30), and - 99.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 343) - - The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00% - probability of being positive (> 0), 99.17% of being significant (> 0.30), and - 0.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 345) - - The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00% - probability of being negative (< 0), 100.00% of being significant (< -0.30), - and 100.00% of being large (< -1.81). The estimation successfully converged - (Rhat = 0.999) but the indices are unreliable (ESS = 586) - - Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT) - framework, we report the median of the posterior distribution and its 95% CI - (Highest Density Interval), along the probability of direction (pd), the - probability of significance and the probability of being large. The thresholds - beyond which the effect is considered as significant (i.e., non-negligible) and - large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the - outcome's SD). Convergence and stability of the Bayesian sampling has been - assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and - Effective Sample Size (ESS), which should be greater than 1000 (Burkner, - 2017)., We fitted a Bayesian linear model (estimated using MCMC sampling with 4 - chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt - (formula: mpg ~ qsec + wt). Priors over parameters were set as uniform - (location = , scale = ) distributions. The model's explanatory power is - substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this - model: - - - The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67% - probability of being positive (> 0), 99.67% of being significant (> 0.30), and - 99.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 343) - - The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00% - probability of being positive (> 0), 99.17% of being significant (> 0.30), and - 0.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 345) - - The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00% - probability of being negative (< 0), 100.00% of being significant (< -0.30), - and 100.00% of being large (< -1.81). The estimation successfully converged - (Rhat = 0.999) but the indices are unreliable (ESS = 586) - - Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT) - framework, we report the median of the posterior distribution and its 95% CI - (Highest Density Interval), along the probability of direction (pd), the - probability of significance and the probability of being large. The thresholds - beyond which the effect is considered as significant (i.e., non-negligible) and - large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the - outcome's SD). Convergence and stability of the Bayesian sampling has been - assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and - Effective Sample Size (ESS), which should be greater than 1000 (Burkner, 2017). - and We fitted a Bayesian linear model (estimated using MCMC sampling with 4 - chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt - (formula: mpg ~ qsec + wt). Priors over parameters were set as student_t - (location = 0.00, scale = 5.40) distributions. The model's explanatory power is - substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this - model: - - - The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67% - probability of being positive (> 0), 99.67% of being significant (> 0.30), and - 99.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 343) - - The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00% - probability of being positive (> 0), 99.17% of being significant (> 0.30), and - 0.33% of being large (> 1.81). The estimation successfully converged (Rhat = - 0.999) but the indices are unreliable (ESS = 345) - - The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00% - probability of being negative (< 0), 100.00% of being significant (< -0.30), - and 100.00% of being large (< -1.81). The estimation successfully converged - (Rhat = 0.999) but the indices are unreliable (ESS = 586) - - Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT) - framework, we report the median of the posterior distribution and its 95% CI - (Highest Density Interval), along the probability of direction (pd), the - probability of significance and the probability of being large. The thresholds - beyond which the effect is considered as significant (i.e., non-negligible) and - large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the - outcome's SD). Convergence and stability of the Bayesian sampling has been - assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and - Effective Sample Size (ESS), which should be greater than 1000 (Burkner, 2017). - diff --git a/tests/testthat/test-report.brmsfit.R b/tests/testthat/test-report.brmsfit.R index 8b5a2f98..f646fac1 100644 --- a/tests/testthat/test-report.brmsfit.R +++ b/tests/testthat/test-report.brmsfit.R @@ -13,9 +13,6 @@ test_that("report.brms", { expect_s3_class(summary(r), "character") expect_s3_class(as.data.frame(r), "data.frame") - set.seed(333) - expect_snapshot(variant = "windows", report(model, verbose = FALSE)) - expect_identical( as.data.frame(r)$Parameter, c( @@ -33,4 +30,8 @@ test_that("report.brms", { c(rep(1, 4), rep(NA, 7)), tolerance = 1e-1 ) + + skip("Skipping because of a .01 decimal difference in snapshots") + set.seed(333) + expect_snapshot(variant = "windows", report(model, verbose = FALSE)) }) diff --git a/tests/testthat/test-report.lm.R b/tests/testthat/test-report.lm.R index 0b182fd9..12a64552 100644 --- a/tests/testthat/test-report.lm.R +++ b/tests/testthat/test-report.lm.R @@ -3,7 +3,7 @@ # Readding back because of a .1 decimal difference in snapshots test_that("report.lm - lm", { - skip("Skipping because of a .1 decimal difference in snapshots") + skip("Skipping because of a .01 decimal difference in snapshots") # lm ------- # simple effect diff --git a/tests/testthat/test-report_performance.R b/tests/testthat/test-report_performance.R index 4e842c32..bbc7616a 100644 --- a/tests/testthat/test-report_performance.R +++ b/tests/testthat/test-report_performance.R @@ -121,7 +121,7 @@ test_that("report_performance Bayesian 2)", { variant = "windows", summary(report_performance(x7)) ) - skip("Skipping because of a .1 decimal difference in snapshots") + skip("Skipping because of a .01 decimal difference in snapshots") expect_snapshot( variant = "windows", report_performance(x7)