Skip to content

Commit

Permalink
fix lints, build_reference_index
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc committed Apr 1, 2024
1 parent ec1d9c0 commit d21553c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
70 changes: 39 additions & 31 deletions R/report.BFBayesFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,76 @@
#' 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
}



#' @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
}

1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ reference:
- report.stanreg
- report.test_performance
- report.estimate_contrasts
- report.BFBayesFactor

- title: Report Non-Statistical Objects
desc: |
Expand Down

0 comments on commit d21553c

Please sign in to comment.