diff --git a/NEWS.md b/NEWS.md index 5a417704..bf442697 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ Bug fixes * Fix `report()` crash when character vector has only one unique value (#578). +* `report()`: fix failure when reporting Kruskal-Wallis tests with degenerate cases (one observation per group) (#454) # report 0.6.3 diff --git a/tests/testthat/_snaps/windows/report.lmer.new.md b/tests/testthat/_snaps/windows/report.lmer.new.md new file mode 100644 index 00000000..564febbe --- /dev/null +++ b/tests/testthat/_snaps/windows/report.lmer.new.md @@ -0,0 +1,45 @@ +# report-lmer + + Code + report(m1) + Output + We fitted a linear mixed model (estimated using REML and nloptwrap optimizer) + to predict Reaction with Days (formula: Reaction ~ Days). The model included + Days as random effects (formula: ~1 + Days | Subject). The model's total + explanatory power is substantial (conditional R2 = 0.80) and the part related + to the fixed effects alone (marginal R2) is of 0.28. The model's intercept, + corresponding to Days = 0, is at 251.41 (95% CI [237.94, 264.87], t(174) = + 36.84, p < .001). Within this model: + + - The effect of Days is statistically significant and positive (beta = 10.47, + 95% CI [7.42, 13.52], t(174) = 6.77, p < .001; Std. beta = 0.54, 95% CI [0.38, + 0.69]) + + Standardized parameters were obtained by fitting the model on a standardized + version of the dataset. 95% Confidence Intervals (CIs) and p-values were + computed using a Wald t-distribution approximation. + +--- + + Code + report(m2) + Message + boundary (singular) fit: see help('isSingular') + boundary (singular) fit: see help('isSingular') + Output + We fitted a linear mixed model (estimated using REML and nloptwrap optimizer) + to predict Reaction with Days (formula: Reaction ~ Days). The model included + mysubgrp as random effects (formula: list(~1 | mysubgrp:mygrp, ~1 | mygrp, ~1 | + Subject)). The model's total explanatory power is substantial (conditional R2 = + 0.71) and the part related to the fixed effects alone (marginal R2) is of 0.28. + The model's intercept, corresponding to Days = 0, is at 252.09 (95% CI [232.50, + 271.69], t(174) = 25.39, p < .001). Within this model: + + - The effect of Days is statistically significant and positive (beta = 10.35, + 95% CI [8.78, 11.93], t(174) = 12.95, p < .001; Std. beta = 0.53, 95% CI [0.45, + 0.61]) + + Standardized parameters were obtained by fitting the model on a standardized + version of the dataset. 95% Confidence Intervals (CIs) and p-values were + computed using a Wald t-distribution approximation. + diff --git a/tests/testthat/test-report.htest-kruskal.R b/tests/testthat/test-report.htest-kruskal.R index 4d518adf..b9580ddb 100644 --- a/tests/testthat/test-report.htest-kruskal.R +++ b/tests/testthat/test-report.htest-kruskal.R @@ -7,3 +7,23 @@ test_that("report.htest-kruskal report", { report(x, verbose = FALSE) ) }) + +test_that("report.htest-kruskal degenerate case (one observation per group)", { + # Test case from issue #454: one observation per group causes CI calculation to fail + n <- 10 + set.seed(123) + df <- data.frame(a = as.factor(1:n), b = rnorm(n)) + # Use the formula interface to allow effectsize to retrieve data + test <- kruskal.test(b ~ a, data = df) + + # Should not fail and should complete quickly - provide data manually + expect_no_error({ + result <- report(test, data = df, verbose = FALSE) + }) + + # Result should contain effect size but no CI due to degenerate case + result <- report(test, data = df, verbose = FALSE) + result_text <- as.character(result) + expect_true(grepl("Epsilon squared \\(rank\\) = 1\\.00", result_text)) + expect_false(grepl("95% CI", result_text)) # No CI should be present +})