Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

η²p for ANOVA repeated measures #406

Closed
jorgesinval opened this issue Jan 14, 2022 · 3 comments
Closed

η²p for ANOVA repeated measures #406

jorgesinval opened this issue Jan 14, 2022 · 3 comments
Assignees
Labels
bug 🐜 Something isn't working consistency 🍎 🍏 enhancement 🔥 New feature or request

Comments

@jorgesinval
Copy link

jorgesinval commented Jan 14, 2022

I am puzzled on how etasquared() is working with car objects for repeated designs:

ds <- data.frame(matrix(data = c(
      116,76,85,50,
      96,93,63,87,
      120,112,89,100,
      110,113,60,60,
      116,75,115,79,
      126,120,101,70,
      86,90,129,65,
      80,105,67,65),
    nrow = 8,
    ncol = 4,
    byrow = T
  ), id = 1:8)
names(ds) <- c("I","II","III","IV","id")

library(car)
#> Loading required package: carData
fit   <- lm(cbind(I,II,III,IV) ~ 1, data=ds)
in_rep    <- data.frame(ind_var=gl(4, 1))
Anova(fit, idata=in_rep, idesign=~ind_var) |> 
effectsize::eta_squared()
#> Note: model has only an intercept; equivalent type-III tests substituted.
#> # Effect Size for ANOVA (Type III)
#> 
#> Parameter | Eta2 (partial) |       95% CI
#> -----------------------------------------
#> ind_var   |           0.78 | [0.04, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at (1).


ds_long <- rstatix::gather(ds,
                             "I", "II", "III", "IV",
                             key = ind_var, value = score)


afex::aov_ez(id = 'id',
       dv = 'score',
       fun_aggregate = mean,
       data = ds_long,
       within = 'ind_var',
       include_aov = T,
       type = "III") |> effectsize::eta_squared()
#> Warning in summary.Anova.mlm(model$Anova): HF eps > 1 treated as 1
#> # Effect Size for ANOVA (Type III)
#> 
#> Parameter | Eta2 (partial) |       95% CI
#> -----------------------------------------
#> ind_var   |           0.41 | [0.09, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at (1).

Created on 2022-01-14 by the reprex package (v2.0.1)

The same data, the same analysis, the same SS... but totally different results. I made it by hand and the second approach (ez object) is correct.

PS: I am aware that the Generalized η² might be more adequate to repeated measures designs. With the first approach is not possible to produce it using generalized =T but with the second one, yes.

@mattansb
Copy link
Member

Originally, I couldn't figure out how to get the raw SS out of an Anova.mlm object, so instead I used the F-to-eta approximation (via F_to_eta2()) which gives only approx results.

But I see that I already solved this elsewhere but just didn't export the function... So now I've taken care of that (:

ds <- data.frame(I = c(116, 96, 120, 110, 116, 126, 86, 80),
                 II = c(76, 93, 112, 113, 75, 120, 90, 105), 
                 III = c(85, 63, 89, 60, 115, 101, 129, 67),
                 IV = c(50, 87, 100, 60, 79, 70, 65, 65),
                 id = 1:8)

ds_long <- data.frame(
  id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
         1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
         1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
         1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L),
  ind_var = c("I", "I", "I", "I", "I", "I", "I", "I", 
              "II", "II", "II", "II", "II", "II", "II", "II", 
              "III", "III", "III", "III", "III", "III", "III", "III", 
              "IV", "IV", "IV", "IV", "IV", "IV", "IV", "IV"),
  score = c(116, 96, 120, 110, 116, 126, 86, 80,
            76, 93, 112, 113, 75, 120, 90, 105, 
            85, 63, 89, 60, 115, 101, 129, 67,
            50, 87, 100, 60, 79, 70, 65, 65)
)


# Car -----
fit <- lm(cbind(I, II, III, IV) ~ 1, data = ds)
in_rep <- data.frame(ind_var = gl(4, 1))
car::Anova(fit, idata = in_rep, idesign =  ~ ind_var) |> 
  effectsize::eta_squared(ci = NULL)
#> Note: model has only an intercept; equivalent type-III tests substituted.
#> Warning in summary.Anova.mlm(model): HF eps > 1 treated as 1
#> # Effect Size for ANOVA (Type III)
#> 
#> Parameter | Eta2 (partial)
#> --------------------------
#> ind_var   |           0.41


afex::aov_ez(id = 'id',
             dv = 'score',
             data = ds_long,
             within = 'ind_var',
             anova_table = list(es = "pes"))
#> Anova Table (Type 3 tests)
#> 
#> Response: score
#>    Effect          df    MSE      F  pes p.value
#> 1 ind_var 2.22, 15.52 481.55 4.86 * .410    .021
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
#> 
#> Sphericity correction method: GG

Created on 2022-01-14 by the reprex package (v2.0.1)

@jorgesinval
Copy link
Author

jorgesinval commented Jan 14, 2022

Excellent! When will you upload that change to the package?

@mattansb mattansb self-assigned this Jan 14, 2022
@mattansb mattansb added bug 🐜 Something isn't working consistency 🍎 🍏 enhancement 🔥 New feature or request labels Jan 14, 2022
@mattansb
Copy link
Member

Already on the main branch of Github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐜 Something isn't working consistency 🍎 🍏 enhancement 🔥 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants