Skip to content

Commit

Permalink
fix #556
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Jan 8, 2025
1 parent a4f78d7 commit 8406d7b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## Bug fixes

* Fixed issue with `model_parameters(<aovlist>, table_wide = TRUE)` with complex error structures ( #556 )

* Fixed issue when printing `model_parameters()` with models from `mgcv::gam()`.

* Fixed issues due to breaking changes in the latest release of the *datawizard*
Expand Down
8 changes: 7 additions & 1 deletion R/methods_aov.R
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ model_parameters.seqanova.svyglm <- model_parameters.aov
wide_anova <- function(x) {
# creating numerator and denominator degrees of freedom
idxResid <- x$Parameter == "Residuals"
if (length(idxResid)) {
if (length(idxResid) >= 1L && any(idxResid)) {
x$df_error <- x$df[idxResid]
x$Sum_Squares_Error <- x$Sum_Squares[idxResid]
x$Mean_Square_Error <- x$Sum_Squares[idxResid]
Expand All @@ -545,6 +545,12 @@ model_parameters.seqanova.svyglm <- model_parameters.aov
if ("Group" %in% colnames(data)) {
data <- split(data, data$Group)
data <- lapply(data, wide_anova)
data <- Filter(function(x) nrow(x) >= 1L, data)
cols <- unique(unlist(lapply(data, colnames)))
data <- lapply(data, function(x) {
x[,setdiff(cols, colnames(x))] <- NA

Check warning on line 551 in R/methods_aov.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/methods_aov.R,line=551,col=10,[commas_linter] Put a space after a comma.
x
})
data <- do.call(rbind, data)
} else {
data <- wide_anova(data)
Expand Down
29 changes: 29 additions & 0 deletions tests/testthat/test-model_parameters.aov.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,32 @@ test_that("model_parameters.anova", {
model <- aov(Sepal.Length ~ Species / Cat1 + Error(Cat2), data = iris)
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149)
})


test_that("model_parameters.aov - table_wide", {
skip_if_not_installed("effectsize")
skip_if_not_installed("datawizard")

data("iris")
# can't use the pipe yet :(
iris_long <- datawizard::data_modify(iris, id = 1:length(Species))

Check warning on line 95 in tests/testthat/test-model_parameters.aov.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-model_parameters.aov.R,line=95,col=51,[seq_linter] Use seq_along(...) instead of 1:length(...), which is likely to be wrong in the empty edge case.
iris_long <- datawizard::data_to_long(iris_long, select = colnames(iris)[1:4])
iris_long <- datawizard::data_separate(iris_long, select = "name", separator = "\\.",
new_columns = c("attribute", "measure"))

mod1 <- stats::aov(
formula = value ~ attribute * measure + Error(id),
data = iris_long
)

mod2 <- stats::aov(
formula = value ~ attribute * measure + Error(id / (attribute * measure)),
data = iris_long
)

mp1 <- model_parameters(mod1, eta_squared = "partial", ci = 0.95, table_wide = TRUE)
mp2 <- model_parameters(mod2, eta_squared = "partial", ci = 0.95, table_wide = TRUE)

expect_identical(nrow(mp1), 3L)
expect_identical(nrow(mp2), 6L)
})

0 comments on commit 8406d7b

Please sign in to comment.