rstatix包anova_test函数设置effect.size='ges'仍返回偏eta平方值的技术问询
rstatix::anova_test() return partial eta squared even when effect.size = "ges"? Let's break down what's happening here and why you're seeing this unexpected behavior:
1. Core Issue: Sum of Squares (SS) Type Mismatch
First, a critical background difference:
aov()uses Type I SS by default, which calculates variance explained in the order variables are entered into the model. That's why youraov()output shows Sepal.Width with an SS of 1.41.rstatix::anova_test()defaults to Type III SS, which tests each variable while controlling for all other variables in the model. This is why youranova_test()result shows Sepal.Width with an SS of 10.953.
sjstats::eta_sq() computes effect sizes based on the Type I SS from aov(), which is why you get the expected eta squared values when setting partial=FALSE.
2. rstatix's Limitation with ANCOVA Models
The main problem is that current versions of rstatix don't correctly compute generalized eta squared (ges) for ANCOVA models (models with continuous covariates like Sepal.Width). Even when you set effect.size = "ges", the package still returns partial eta squared (pes) instead.
Here's the breakdown of the calculations:
- Partial eta squared is calculated as
SS_effect / (SS_effect + SS_residual). For your Sepal.Width term, that's10.953 / (10.953 + 28.004) ≈ 0.281—exactly what you see in your results. - Generalized eta squared should be
SS_effect / SS_total, whereSS_totalincludes all effect SS plus residual SS. For your Type III SS model,SS_total = 10.953 + 72.752 + 28.004 = 111.709, so Sepal.Width's ges would be10.953 / 111.709 ≈ 0.098—but rstatix doesn't compute this value.
This appears to be a gap in rstatix's implementation: its ges calculation works for pure ANOVA models (no continuous covariates) but fails to adapt to ANCOVA scenarios.
3. Workarounds to Get the Correct Effect Sizes
Option 1: Stick with aov() + sjstats::eta_sq()
If Type I SS aligns with your analysis goals, this combination will reliably give you both eta squared and partial eta squared exactly as you expect.
Option 2: Manually Calculate Generalized Eta Squared for Type III SS
If you need Type III SS-based ges, compute it using the values from anova_test():
# Extract the ANOVA table from rstatix anova_table <- get_anova_table(aov_ges) # Calculate total SS (sum of all effect SS + residual SS) total_ss <- sum(anova_table$SSn) + anova_table$SSd[1] # Compute generalized eta squared for each term anova_table$ges <- anova_table$SSn / total_ss # View the updated table with ges anova_table
This will give you the correct generalized eta squared values for your ANCOVA model.
Option 3: Check for rstatix Updates or Report the Issue
You can check the rstatix GitHub repository for newer versions—this bug might have been fixed in recent updates. If not, submitting an issue describing your ANCOVA use case could help the developer address this limitation.
内容的提问来源于stack exchange,提问作者Georgia Clay

