-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] report() for BayesFactor objects (#420)
* add * Update report.BFBayesFactor.R * exact=TRUE * docs * Update DESCRIPTION * fix lints, build_reference_index * NEWS, pkgdown * update snapshots, document * skip test, update wordlist * delete problematic report.brms snapshot --------- Co-authored-by: Mattan S. Ben-Shachar <mattansb@msbstats.info> Co-authored-by: Rémi Thériault <13123390+rempsyc@users.noreply.github.com>
- Loading branch information
1 parent
ed9e9d0
commit a2c7709
Showing
12 changed files
with
139 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#' 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. | ||
#' @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{ | ||
#' 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") | ||
#' | ||
#' rez <- BayesFactor::correlationBF(iris$Sepal.Width, iris$Sepal.Length) | ||
#' report(rez) | ||
#' } | ||
#' | ||
#' @export | ||
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\")." | ||
) | ||
x <- x[1] | ||
} | ||
|
||
param <- parameters::parameters(x[1], ...) | ||
bf <- param$BF | ||
other_dir <- ifelse(bf < 1, "h0", "h1") | ||
|
||
|
||
if (other_dir == "h1") { | ||
other_text <- paste0( | ||
"There is ", | ||
effectsize::interpret_bf(bf, ...), | ||
" ", | ||
h1, | ||
" over ", | ||
h0, | ||
" (", report_statistics(x, ...), ")." | ||
) | ||
} else { | ||
other_text <- paste0( | ||
"There is ", | ||
effectsize::interpret_bf(1 / bf, ...), | ||
" ", | ||
h0, | ||
" over ", | ||
h1, | ||
" (", report_statistics(x, ...), ")." | ||
) | ||
} | ||
other_text | ||
} | ||
|
||
|
||
|
||
#' @rdname report.BFBayesFactor | ||
#' @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 | ||
other_text <- ifelse(bf < 1, | ||
insight::format_bf(1 / bf, name = "BF01", ...), | ||
insight::format_bf(bf, name = "BF10", ...) | ||
) | ||
other_text | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.