Skip to content

Commit 03b3480

Browse files
M-ColleystrengejackeCopilot
authored
Solve #598 (#600)
* Handle logical values in report_intercept function * Update test-report_intercept.R * Update NEWS.md for version 0.6.3.1 Fixed display issue for logical predictors in report() function. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix formatting of expect_identical in test-report_intercept * Update test-report_intercept.R * Bump version from 0.6.3.1 to 0.6.4.1 --------- Co-authored-by: Daniel <mail@danielluedecke.de> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 83ca663 commit 03b3480

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# report (devel)
2+
3+
Bug fixes
4+
5+
* Fixed an issue in `report()` where the reference level for logical predictors was incorrectly displayed as `[?]` instead of `FALSE` for the intercept (@M-Colley, #598).
6+
17
# report 0.6.4
28

39
New features

R/report_intercept.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ print.report_intercept <- function(x, ...) {
9898
intercept_text,
9999
paste0(col, " = ", levels(intercept_data[[col]])[ref_level])
100100
)
101+
} else if (is.logical(intercept_data[[col]])) {
102+
logical_factor <- as.factor(intercept_data[[col]])
103+
ref_level <- .find_reference_level(logical_factor)
104+
intercept_text <- c(
105+
intercept_text,
106+
paste0(col, " = ", levels(logical_factor)[ref_level])
107+
)
101108
} else {
102109
intercept_text <- c(intercept_text, paste0(col, " = [?]"))
103110
}

tests/testthat/test-report_intercept.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ test_that("reflevel", {
4949
as.character(report_intercept(m3)),
5050
"The model's intercept, corresponding to f = 1, is at 0.17 (95% CI [-0.47, 0.81], t(27) = 0.55, p = 0.584)."
5151
)
52+
53+
# Logical predictor
54+
on.exit(data("mtcars"), add = TRUE)
55+
56+
mtcars$more_than_4_cyl <- as.logical(mtcars$cyl > 4)
57+
m4 <- lm(mpg ~ more_than_4_cyl, data = mtcars)
58+
expect_identical(
59+
as.character(report_intercept(m4)),
60+
"The model's intercept, corresponding to more_than_4_cyl = FALSE, is at 26.66 (95% CI [24.41, 28.92], t(30) = 24.16, p < .001)."
61+
)
5262
})

0 commit comments

Comments
 (0)