Skip to content

Commit

Permalink
tighten regex in car::linearHypothesis() tidier (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Sep 6, 2023
1 parent 9c6f507 commit db2ca13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

* Moved forward with deprecation of tidiers for objects from the sp package. See resources linked in [tidymodels/broom#1142](https://github.com/tidymodels/broom/issues/1142) for more information on migration from retiring spatial packages.

* Corrected confidence interval values for precision components in `tidy.betareg()` output (#1169).

* Fixed bug in tidier for `car::linearHypothesis()` output with long formulas (#1171).

* Added support for columns `adj.r.squared` and `npar` in `glance()` method for objects outputted from `mgcv::gam()` (#1172).

* Corrected confidence interval values for precision components in `tidy.betareg()` output.

# broom 1.0.5

Expand Down
2 changes: 1 addition & 1 deletion R/stats-anova-tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ tidy.anova <- function(x, ...) {
# Drop unrestricted model (not interesting in linear hypothesis tests)
# Use formula to subset if available (e.g. with car::linearHypothesis)
if (length(mod_lines) != 0) {
idx <- sub(".*: ", "", strsplit(mod_lines, "\n")[[1]])
idx <- sub("Model \\d*: ", "", strsplit(mod_lines, "\\nModel \\d*: ")[[1]])
idx <- idx != "restricted model"
ret <- ret[idx, , drop = FALSE]
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-car.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ test_that("tidy car::Anova coxph", {
check_dims(td2, expected_rows = 2, expected_cols = 5)
check_dims(td3, expected_rows = 2, expected_cols = 4)
})

test_that("tidy car::linearHypothesis with long formulas (#1171)", {
reg_long <-
lm(
Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality,
data = swiss
)

test_long <- car::linearHypothesis(reg_long, hypothesis.matrix = c(0,1, 0, 0, 0, -1))

td <- broom::tidy(test_long)
check_dims(td, expected_rows = 1, expected_cols = 10)
})

0 comments on commit db2ca13

Please sign in to comment.