Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ Suggests:
BayesFactor,
brms,
collapse,
GLMMadaptive,
glmmTMB,
ivreg,
knitr,
lavaan,
lme4,
loo,
nlme,
dplyr,
Formula,
rmarkdown,
Expand Down
12 changes: 8 additions & 4 deletions R/report.BFBayesFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) {
bf <- param$BF
other_dir <- ifelse(bf < 1, "h0", "h1")


if (other_dir == "h1") {
other_text <- paste0(
"There is ",
Expand All @@ -46,7 +45,9 @@ report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) {
h1,
" over ",
h0,
" (", report_statistics(x, ...), ")."
" (",
report_statistics(x, ...),
")."
)
} else {
other_text <- paste0(
Expand All @@ -56,7 +57,9 @@ report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) {
h0,
" over ",
h1,
" (", report_statistics(x, ...), ")."
" (",
report_statistics(x, ...),
")."
)
}
other_text
Expand All @@ -78,7 +81,8 @@ report_statistics.BFBayesFactor <- function(x, table = NULL, ...) {
}

bf <- table$BF
other_text <- ifelse(bf < 1,
other_text <- ifelse(
bf < 1,
insight::format_bf(1 / bf, name = "BF01", ...),
insight::format_bf(bf, name = "BF10", ...)
)
Expand Down
124 changes: 124 additions & 0 deletions tests/testthat/_snaps/windows/report.brmsfit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# 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).

120 changes: 120 additions & 0 deletions tests/testthat/test-cite_easystats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
test_that("cite_easystats() works with default parameters", {
result <- cite_easystats()
expect_s3_class(result, "cite_easystats")
expect_type(result, "list")
expect_named(result, c("intext", "refs"))
expect_type(result$intext, "character")
expect_type(result$refs, "character")
expect_match(result$intext, "easystats")
expect_match(result$refs, "Lüdecke")
})

test_that("cite_easystats() works with different formats", {
# Text format (default)
result_text <- cite_easystats(format = "text")
expect_match(result_text$intext, "collection of packages")
expect_match(result_text$refs, "- Lüdecke")

# Markdown format
result_md <- cite_easystats(format = "markdown")
expect_match(result_md$intext, "@easystatsPackage")
expect_match(result_md$refs, "id: easystatsPackage")

# BibLaTeX format
result_bib <- cite_easystats(format = "biblatex")
expect_match(result_bib$intext, "\\\\cite\\{")
expect_match(result_bib$refs, "@software\\{")
})

test_that("cite_easystats() works with different package specifications", {
# Single package
result_single <- cite_easystats(packages = "insight")
expect_true(any(grepl("insight", result_single$refs, fixed = TRUE)))

# Multiple specific packages
result_multi <- cite_easystats(packages = c("insight", "parameters"))
expect_true(any(grepl("insight", result_multi$refs, fixed = TRUE)))
expect_true(any(grepl("parameters", result_multi$refs, fixed = TRUE)))
})

test_that("cite_easystats() handles prefix and suffix correctly", {
# With default prefix/suffix
result_default <- cite_easystats()
expect_match(result_default$intext, "^Analyses were conducted")
expect_match(result_default$intext, "\\.$")

# Without prefix
result_no_prefix <- cite_easystats(intext_prefix = FALSE)
expect_false(startsWith(result_no_prefix$intext, "Analyses were conducted"))

# Without suffix
result_no_suffix <- cite_easystats(intext_suffix = FALSE)
expect_false(endsWith(result_no_suffix$intext, "."))

# Custom prefix and suffix
result_custom <- cite_easystats(
intext_prefix = "Custom prefix ",
intext_suffix = " custom suffix"
)
expect_match(result_custom$intext, "^Custom prefix")
expect_match(result_custom$intext, "custom suffix$")
})

test_that("cite_easystats() handles missing packages gracefully", {
# Test with non-existent package (should show warning and omit)
expect_message(
cite_easystats(packages = c("insight", "nonexistent_package")),
"not installed"
)

# Now get the result for testing
suppressMessages({
result <- cite_easystats(packages = c("insight", "nonexistent_package"))
})
expect_true(any(grepl("insight", result$refs, fixed = TRUE)))
expect_false(any(grepl("nonexistent", result$refs, fixed = TRUE)))
})

test_that("print.cite_easystats() works correctly", {
result <- cite_easystats()

# Test different 'what' arguments
expect_output(print(result, what = "all"), "Thanks for crediting")
expect_output(print(result, what = "intext"), "easystats")
expect_output(print(result, what = "refs"), "Lüdecke")

# Test with 'cite' and 'bib' aliases
expect_output(print(result, what = "cite"), "easystats")
expect_output(print(result, what = "bib"), "Lüdecke")
})

test_that("summary.cite_easystats() works correctly", {
result <- cite_easystats()

# Test different 'what' arguments
expect_output(summary(result, what = "all"), "Citations")
expect_output(summary(result, what = "intext"), "easystats")
expect_output(summary(result, what = "refs"), "Lüdecke")

# Test with 'cite' and 'bib' aliases
expect_output(summary(result, what = "cite"), "easystats")
expect_output(summary(result, what = "bib"), "Lüdecke")
})

test_that(".disamguation_letters() helper function works", {
# Test with logical vector
result1 <- report:::.disamguation_letters(c(TRUE, FALSE, TRUE))
expect_identical(result1, c("a", "", "b"))

result2 <- report:::.disamguation_letters(TRUE)
expect_identical(result2, "a") # Single TRUE should return "a", not empty

result3 <- report:::.disamguation_letters(c(FALSE, FALSE))
expect_identical(result3, c("", ""))

# Test error handling
expect_error(
report:::.disamguation_letters(c(1, 2, 3)),
"must be a logical vector"
)
})
Loading
Loading