# 1. Raw-argument interface. Bargman's (1970) 5-group one-way ANOVA,
# also used in Venables (1975), Fleishman (1980), and Steiger (2004):
# 11 subjects per group, observed F = 11.221.
eta_squared(F_value = 11.221, df_effect = 4, df_error = 50)
# 2. One way ANOVA from a fitted model (depression_bdi: three
# treatment arms, 10 per arm, N = 30).
fit_one <- aov(bdi_post ~ condition, data = depression_bdi)
eta_squared(fit_one)
# 3. Factorial ANOVA: partial eta squared per effect (pygmalion
# data: expectancy treatment x grade, 2 x 6 with unequal cell
# sizes, N = 310). The treatment is manipulated; grade is a
# measured classification of the pupils.
fit_factorial <- aov(iq_8 ~ treatment * factor(grade), data = pygmalion)
eta_squared(fit_factorial)
# 4. Within-subjects (repeated measures) ANOVA. Simulated 20-subject
# x 3-time design; each subject is measured at Pre, Mid, Post.
set.seed(113)
n <- 20
rm_data <- data.frame(
subject = factor(rep(seq_len(n), each = 3)),
time = factor(rep(c("Pre", "Mid", "Post"), n),
levels = c("Pre", "Mid", "Post")),
y = rnorm(n, sd = 1.5)[rep(seq_len(n), each = 3)] +
0.7 * rep(1:3, n) + rnorm(n * 3, sd = 1.2)
)
fit_rm <- aov(y ~ time + Error(subject/time), data = rm_data)
eta_squared(fit_rm) # 'stratum' column identifies the within-subjects error
Run the code above in your browser using DataLab