Skip to content

Commit 4445de8

Browse files
Copilotrempsyc
andauthored
Investigate and fix 0% test coverage issue + comprehensive linting improvements (#569) let's merge this baby [skip ci]
* Initial plan * Complete: Massive test coverage increase from 232 to 499 tests (0 failures) Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * styler [skip ci] * Fix test failures and apply styling - address coverage analysis issue Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * Fix linting issues and investigate coverage problem deeper Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * comment out skip_if_not_installed("rstan", "2.26.0") [skip ci] * Add explicit test files for functions with 0% coverage Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * style [skip ci] * Fix BFBayesFactor test failures and address linting issues in new test files Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * Fix MixMod test failure by using proper GLMMadaptive example with binomial family Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * suppress warning data recovery [skip ci] * Fix unstated dependencies warning and comprehensive linting fixes Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * Fix namespacing in test files to resolve function resolution errors Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * styler [skip ci] * trigger tests * Fix linting issues and unstated dependencies warning in test files Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * Add missing test packages to DESCRIPTION Suggests and optimize namespacing Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com>
1 parent 793d7fc commit 4445de8

21 files changed

Lines changed: 1633 additions & 26 deletions

DESCRIPTION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ Suggests:
6868
BayesFactor,
6969
brms,
7070
collapse,
71+
GLMMadaptive,
72+
glmmTMB,
7173
ivreg,
7274
knitr,
7375
lavaan,
7476
lme4,
77+
loo,
78+
nlme,
7579
dplyr,
7680
Formula,
7781
rmarkdown,

R/report.BFBayesFactor.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) {
3737
bf <- param$BF
3838
other_dir <- ifelse(bf < 1, "h0", "h1")
3939

40-
4140
if (other_dir == "h1") {
4241
other_text <- paste0(
4342
"There is ",
@@ -46,7 +45,9 @@ report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) {
4645
h1,
4746
" over ",
4847
h0,
49-
" (", report_statistics(x, ...), ")."
48+
" (",
49+
report_statistics(x, ...),
50+
")."
5051
)
5152
} else {
5253
other_text <- paste0(
@@ -56,7 +57,9 @@ report.BFBayesFactor <- function(x, h0 = "H0", h1 = "H1", ...) {
5657
h0,
5758
" over ",
5859
h1,
59-
" (", report_statistics(x, ...), ")."
60+
" (",
61+
report_statistics(x, ...),
62+
")."
6063
)
6164
}
6265
other_text
@@ -78,7 +81,8 @@ report_statistics.BFBayesFactor <- function(x, table = NULL, ...) {
7881
}
7982

8083
bf <- table$BF
81-
other_text <- ifelse(bf < 1,
84+
other_text <- ifelse(
85+
bf < 1,
8286
insight::format_bf(1 / bf, name = "BF01", ...),
8387
insight::format_bf(bf, name = "BF10", ...)
8488
)
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# report.brms
2+
3+
Code
4+
report(model, verbose = FALSE)
5+
Message
6+
Start sampling
7+
Output
8+
We fitted a Bayesian linear model (estimated using MCMC sampling with 4 chains
9+
of 300 iterations and a warmup of 150) to predict mpg with qsec and wt
10+
(formula: mpg ~ qsec + wt). Priors over parameters were set as student_t
11+
(location = 19.20, scale = 5.40) distributions. The model's explanatory power
12+
is substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this
13+
model:
14+
15+
- The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67%
16+
probability of being positive (> 0), 99.67% of being significant (> 0.30), and
17+
99.33% of being large (> 1.81). The estimation successfully converged (Rhat =
18+
0.999) but the indices are unreliable (ESS = 343)
19+
- The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00%
20+
probability of being positive (> 0), 99.17% of being significant (> 0.30), and
21+
0.33% of being large (> 1.81). The estimation successfully converged (Rhat =
22+
0.999) but the indices are unreliable (ESS = 345)
23+
- The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00%
24+
probability of being negative (< 0), 100.00% of being significant (< -0.30),
25+
and 100.00% of being large (< -1.81). The estimation successfully converged
26+
(Rhat = 0.999) but the indices are unreliable (ESS = 586)
27+
28+
Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT)
29+
framework, we report the median of the posterior distribution and its 95% CI
30+
(Highest Density Interval), along the probability of direction (pd), the
31+
probability of significance and the probability of being large. The thresholds
32+
beyond which the effect is considered as significant (i.e., non-negligible) and
33+
large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the
34+
outcome's SD). Convergence and stability of the Bayesian sampling has been
35+
assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and
36+
Effective Sample Size (ESS), which should be greater than 1000 (Burkner,
37+
2017)., We fitted a Bayesian linear model (estimated using MCMC sampling with 4
38+
chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt
39+
(formula: mpg ~ qsec + wt). Priors over parameters were set as uniform
40+
(location = , scale = ) distributions. The model's explanatory power is
41+
substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this
42+
model:
43+
44+
- The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67%
45+
probability of being positive (> 0), 99.67% of being significant (> 0.30), and
46+
99.33% of being large (> 1.81). The estimation successfully converged (Rhat =
47+
0.999) but the indices are unreliable (ESS = 343)
48+
- The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00%
49+
probability of being positive (> 0), 99.17% of being significant (> 0.30), and
50+
0.33% of being large (> 1.81). The estimation successfully converged (Rhat =
51+
0.999) but the indices are unreliable (ESS = 345)
52+
- The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00%
53+
probability of being negative (< 0), 100.00% of being significant (< -0.30),
54+
and 100.00% of being large (< -1.81). The estimation successfully converged
55+
(Rhat = 0.999) but the indices are unreliable (ESS = 586)
56+
57+
Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT)
58+
framework, we report the median of the posterior distribution and its 95% CI
59+
(Highest Density Interval), along the probability of direction (pd), the
60+
probability of significance and the probability of being large. The thresholds
61+
beyond which the effect is considered as significant (i.e., non-negligible) and
62+
large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the
63+
outcome's SD). Convergence and stability of the Bayesian sampling has been
64+
assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and
65+
Effective Sample Size (ESS), which should be greater than 1000 (Burkner,
66+
2017)., We fitted a Bayesian linear model (estimated using MCMC sampling with 4
67+
chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt
68+
(formula: mpg ~ qsec + wt). Priors over parameters were set as uniform
69+
(location = , scale = ) distributions. The model's explanatory power is
70+
substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this
71+
model:
72+
73+
- The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67%
74+
probability of being positive (> 0), 99.67% of being significant (> 0.30), and
75+
99.33% of being large (> 1.81). The estimation successfully converged (Rhat =
76+
0.999) but the indices are unreliable (ESS = 343)
77+
- The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00%
78+
probability of being positive (> 0), 99.17% of being significant (> 0.30), and
79+
0.33% of being large (> 1.81). The estimation successfully converged (Rhat =
80+
0.999) but the indices are unreliable (ESS = 345)
81+
- The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00%
82+
probability of being negative (< 0), 100.00% of being significant (< -0.30),
83+
and 100.00% of being large (< -1.81). The estimation successfully converged
84+
(Rhat = 0.999) but the indices are unreliable (ESS = 586)
85+
86+
Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT)
87+
framework, we report the median of the posterior distribution and its 95% CI
88+
(Highest Density Interval), along the probability of direction (pd), the
89+
probability of significance and the probability of being large. The thresholds
90+
beyond which the effect is considered as significant (i.e., non-negligible) and
91+
large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the
92+
outcome's SD). Convergence and stability of the Bayesian sampling has been
93+
assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and
94+
Effective Sample Size (ESS), which should be greater than 1000 (Burkner, 2017).
95+
and We fitted a Bayesian linear model (estimated using MCMC sampling with 4
96+
chains of 300 iterations and a warmup of 150) to predict mpg with qsec and wt
97+
(formula: mpg ~ qsec + wt). Priors over parameters were set as student_t
98+
(location = 0.00, scale = 5.40) distributions. The model's explanatory power is
99+
substantial (R2 = 0.82, 95% CI [0.75, 0.85], adj. R2 = 0.79). Within this
100+
model:
101+
102+
- The effect of b Intercept (Median = 19.23, 95% CI [6.80, 31.02]) has a 99.67%
103+
probability of being positive (> 0), 99.67% of being significant (> 0.30), and
104+
99.33% of being large (> 1.81). The estimation successfully converged (Rhat =
105+
0.999) but the indices are unreliable (ESS = 343)
106+
- The effect of b qsec (Median = 0.95, 95% CI [0.41, 1.56]) has a 100.00%
107+
probability of being positive (> 0), 99.17% of being significant (> 0.30), and
108+
0.33% of being large (> 1.81). The estimation successfully converged (Rhat =
109+
0.999) but the indices are unreliable (ESS = 345)
110+
- The effect of b wt (Median = -5.02, 95% CI [-6.06, -4.09]) has a 100.00%
111+
probability of being negative (< 0), 100.00% of being significant (< -0.30),
112+
and 100.00% of being large (< -1.81). The estimation successfully converged
113+
(Rhat = 0.999) but the indices are unreliable (ESS = 586)
114+
115+
Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT)
116+
framework, we report the median of the posterior distribution and its 95% CI
117+
(Highest Density Interval), along the probability of direction (pd), the
118+
probability of significance and the probability of being large. The thresholds
119+
beyond which the effect is considered as significant (i.e., non-negligible) and
120+
large are |0.30| and |1.81| (corresponding respectively to 0.05 and 0.30 of the
121+
outcome's SD). Convergence and stability of the Bayesian sampling has been
122+
assessed using R-hat, which should be below 1.01 (Vehtari et al., 2019), and
123+
Effective Sample Size (ESS), which should be greater than 1000 (Burkner, 2017).
124+
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
test_that("cite_easystats() works with default parameters", {
2+
result <- cite_easystats()
3+
expect_s3_class(result, "cite_easystats")
4+
expect_type(result, "list")
5+
expect_named(result, c("intext", "refs"))
6+
expect_type(result$intext, "character")
7+
expect_type(result$refs, "character")
8+
expect_match(result$intext, "easystats")
9+
expect_match(result$refs, "Lüdecke")
10+
})
11+
12+
test_that("cite_easystats() works with different formats", {
13+
# Text format (default)
14+
result_text <- cite_easystats(format = "text")
15+
expect_match(result_text$intext, "collection of packages")
16+
expect_match(result_text$refs, "- Lüdecke")
17+
18+
# Markdown format
19+
result_md <- cite_easystats(format = "markdown")
20+
expect_match(result_md$intext, "@easystatsPackage")
21+
expect_match(result_md$refs, "id: easystatsPackage")
22+
23+
# BibLaTeX format
24+
result_bib <- cite_easystats(format = "biblatex")
25+
expect_match(result_bib$intext, "\\\\cite\\{")
26+
expect_match(result_bib$refs, "@software\\{")
27+
})
28+
29+
test_that("cite_easystats() works with different package specifications", {
30+
# Single package
31+
result_single <- cite_easystats(packages = "insight")
32+
expect_true(any(grepl("insight", result_single$refs, fixed = TRUE)))
33+
34+
# Multiple specific packages
35+
result_multi <- cite_easystats(packages = c("insight", "parameters"))
36+
expect_true(any(grepl("insight", result_multi$refs, fixed = TRUE)))
37+
expect_true(any(grepl("parameters", result_multi$refs, fixed = TRUE)))
38+
})
39+
40+
test_that("cite_easystats() handles prefix and suffix correctly", {
41+
# With default prefix/suffix
42+
result_default <- cite_easystats()
43+
expect_match(result_default$intext, "^Analyses were conducted")
44+
expect_match(result_default$intext, "\\.$")
45+
46+
# Without prefix
47+
result_no_prefix <- cite_easystats(intext_prefix = FALSE)
48+
expect_false(startsWith(result_no_prefix$intext, "Analyses were conducted"))
49+
50+
# Without suffix
51+
result_no_suffix <- cite_easystats(intext_suffix = FALSE)
52+
expect_false(endsWith(result_no_suffix$intext, "."))
53+
54+
# Custom prefix and suffix
55+
result_custom <- cite_easystats(
56+
intext_prefix = "Custom prefix ",
57+
intext_suffix = " custom suffix"
58+
)
59+
expect_match(result_custom$intext, "^Custom prefix")
60+
expect_match(result_custom$intext, "custom suffix$")
61+
})
62+
63+
test_that("cite_easystats() handles missing packages gracefully", {
64+
# Test with non-existent package (should show warning and omit)
65+
expect_message(
66+
cite_easystats(packages = c("insight", "nonexistent_package")),
67+
"not installed"
68+
)
69+
70+
# Now get the result for testing
71+
suppressMessages({
72+
result <- cite_easystats(packages = c("insight", "nonexistent_package"))
73+
})
74+
expect_true(any(grepl("insight", result$refs, fixed = TRUE)))
75+
expect_false(any(grepl("nonexistent", result$refs, fixed = TRUE)))
76+
})
77+
78+
test_that("print.cite_easystats() works correctly", {
79+
result <- cite_easystats()
80+
81+
# Test different 'what' arguments
82+
expect_output(print(result, what = "all"), "Thanks for crediting")
83+
expect_output(print(result, what = "intext"), "easystats")
84+
expect_output(print(result, what = "refs"), "Lüdecke")
85+
86+
# Test with 'cite' and 'bib' aliases
87+
expect_output(print(result, what = "cite"), "easystats")
88+
expect_output(print(result, what = "bib"), "Lüdecke")
89+
})
90+
91+
test_that("summary.cite_easystats() works correctly", {
92+
result <- cite_easystats()
93+
94+
# Test different 'what' arguments
95+
expect_output(summary(result, what = "all"), "Citations")
96+
expect_output(summary(result, what = "intext"), "easystats")
97+
expect_output(summary(result, what = "refs"), "Lüdecke")
98+
99+
# Test with 'cite' and 'bib' aliases
100+
expect_output(summary(result, what = "cite"), "easystats")
101+
expect_output(summary(result, what = "bib"), "Lüdecke")
102+
})
103+
104+
test_that(".disamguation_letters() helper function works", {
105+
# Test with logical vector
106+
result1 <- report:::.disamguation_letters(c(TRUE, FALSE, TRUE))
107+
expect_identical(result1, c("a", "", "b"))
108+
109+
result2 <- report:::.disamguation_letters(TRUE)
110+
expect_identical(result2, "a") # Single TRUE should return "a", not empty
111+
112+
result3 <- report:::.disamguation_letters(c(FALSE, FALSE))
113+
expect_identical(result3, c("", ""))
114+
115+
# Test error handling
116+
expect_error(
117+
report:::.disamguation_letters(c(1, 2, 3)),
118+
"must be a logical vector"
119+
)
120+
})

0 commit comments

Comments
 (0)