You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

rstatix包anova_test函数设置effect.size='ges'仍返回偏eta平方值的技术问询

Why does 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 your aov() 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 your anova_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's 10.953 / (10.953 + 28.004) ≈ 0.281—exactly what you see in your results.
  • Generalized eta squared should be SS_effect / SS_total, where SS_total includes 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 be 10.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 18:28:13