Skip to content

Commit d431017

Browse files
authored
Fix eta_squared() when factors have reprex-mathing names (#699)
* fix #697
1 parent ffda13b commit d431017

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: effectsize
33
Title: Indices of Effect Size
4-
Version: 1.0.2
4+
Version: 1.0.2.0000001
55
Authors@R:
66
c(person(given = "Mattan S.",
77
family = "Ben-Shachar",

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# effectsize 1.0.x
2+
3+
## Bug fixes
4+
5+
- `eta_squared(<afex> / <Anova.mlm>)` with partially overlapping factor names now return correct effect sizes ( #697 )
6+
17
# effectsize 1.0.2
28

39
## New features

R/eta_squared-methods.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
within_subj <- sapply(within_subj, paste, collapse = ":")
153153
within_subj <- within_subj[order(ns)]
154154
within_subj <- Filter(function(x) nzchar(x, keepNA = TRUE), within_subj)
155-
l <- sapply(within_subj, grepl, x = aov_tab$Parameter, simplify = TRUE)
155+
l <- sapply(paste0("\\b", within_subj, "\\b"), grepl, x = aov_tab$Parameter, simplify = TRUE)
156156
l <- apply(l, 1, function(x) if (any(x)) max(which(x)) else 0)
157157
l <- c(NA, within_subj)[l + 1]
158158
l <- sapply(l, function(x) paste0(stats::na.omit(c(id, x)), collapse = ":"))

tests/testthat/test-eta_squared.R

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,53 @@ test_that("Anova.mlm Manova", {
779779
expect_equal(A1[c(2:4, 6:7), ], A2[c(2:4, 6:7), -1], ignore_attr = TRUE)
780780
})
781781

782+
test_that("Anova.mlm / afex | overlapping factor names", {
783+
skip_if_not_installed("car")
784+
skip_if_not_installed("afex")
785+
786+
data <- data.frame(
787+
subject = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 9L, 10L, 9L, 10L, 9L, 10L, 9L, 10L),
788+
XBlock = factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), labels = c("a1", "a2")),
789+
Block = factor(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), labels = c("aa1", "aa2")),
790+
C = factor(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), labels = c("C_c1", "C_c2")),
791+
y = c(-0.09, -0.29, 0.13, 0.06, 0.17, -0.01, 0.07, 0.27, 0.05, -0.01, -0.07, -0.05, 0.15, 0.12, 0.09, 0.26)
792+
)
793+
contrasts(data$XBlock) <- contr.sum
794+
data$X <- data$XBlock
795+
796+
797+
# list partial eta_squared:
798+
aov_overlap <- afex::aov_ez(
799+
"subject", "y", data,
800+
between = "XBlock",
801+
within = c("Block", "C"),
802+
anova_table = list(es = "pes")
803+
)
804+
805+
aov_nooverlap <- afex::aov_ez(
806+
"subject", "y", data,
807+
between = "X",
808+
within = c("Block", "C"),
809+
anova_table = list(es = "pes")
810+
)
811+
812+
expect_equal(
813+
aov_overlap$anova_table$pes,
814+
eta_squared(aov_overlap)$Eta2_partial
815+
)
816+
817+
expect_equal(
818+
eta_squared(aov_overlap)$Eta2_partial,
819+
eta_squared(aov_nooverlap)$Eta2_partial
820+
)
821+
822+
expect_equal(
823+
eta_squared(aov_overlap)$Eta2_partial,
824+
eta_squared(aov_overlap$Anova)$Eta2_partial
825+
)
826+
})
827+
828+
782829
## merMod --------------------
783830

784831
test_that("merMod and lmerModLmerTest", {

0 commit comments

Comments
 (0)