[英]Post hoc test in R for repeated measures ANOVA with 2 within-variables
比如说,我有一个包含 30 个参与者 (ppt_id) 的全因子设计,每个参与者都在 4 个条件下进行了测试:
(左侧+蓝色)AND(左侧+红色)AND(右侧+蓝色)AND(右侧+红色)
我的因变量是反应时间(RT)。
df = matrix(nrow = 120, ncol = 0)
df = as.data.frame(df)
df$ppt_id = c(rep(c(1:30),4))
df$color = c(rep("red", 60), rep("blue", 60))
df$side = c(rep(c(rep("left", 30), rep("right", 30)),2))
df$RT = c(rnorm(30, 600, 50),
rnorm(30, 650, 50),
rnorm(30, 700, 50),
rnorm(30, 600, 50))
现在,我计算 rmANOVA 并发现因素 Side 和 Color 之间存在显着的交互作用:
anova_test(
data = df,
dv = RT,
wid = ppt_id,
within = c(color, side),
effect.size = "pes")
如何在 R 中对所有条件进行多次比较(事后测试)? 我发现的只是一个具有两个以上水平的变量(单向方差分析)或混合设计(即一个变量之间和一个变量内)的函数。
一种选择可能是使用afex
包来拟合 ANOVA 和marginaleffects
效应包来计算对比度。 (免责声明:我是marginaleffects
的作者。)
首先,拟合模型:
library(marginaleffects)
library(afex)
df = matrix(nrow = 120, ncol = 0)
df = as.data.frame(df)
df$ppt_id = c(rep(c(1:30),4))
df$color = c(rep("red", 60), rep("blue", 60))
df$side = c(rep(c(rep("left", 30), rep("right", 30)),2))
df$RT = c(rnorm(30, 600, 50),
rnorm(30, 650, 50),
rnorm(30, 700, 50),
rnorm(30, 600, 50))
mod <- aov_ez(
id = "ppt_id",
dv = "RT",
within = c("side", "color"),
data = df)
然后,进行事后处理以获得对比。 这将告诉您当我们操纵解释器(及其成对组合)时,模型预测的结果值如何变化:
cmp <- comparisons(
# the model
mod,
# hold other regressors at their means if there are any
newdata = "mean",
# vector of variables we want to "manipulate" in the contrast
variables = c("side", "color"),
# we care about interactions
interactions = TRUE)
summary(cmp)
#> Average contrasts
#> side color Effect Std. Error z value Pr(>|z|)
#> 1 left - left blue - red 110.489 10.71 10.3148 < 2.22e-16
#> 2 right - left red - red 51.055 13.84 3.6896 0.00022457
#> 3 right - left blue - red 6.274 12.19 0.5147 0.60674367
#> 2.5 % 97.5 %
#> 1 89.49 131.48
#> 2 23.93 78.18
#> 3 -17.62 30.16
#>
#> Model type: afex_aov
#> Prediction type: response
这里有一个关于对比的详细插图: https ://vincentarelbundock.github.io/marginaleffects/articles/contrasts.html
也许我无法理解@Vincent 的答案,或者我没有清楚地解释我需要什么。
理想情况下,我想得到一个包含该数据集所有可能比较的表,即应该有六个比较(因为有 4 个可能的条件),类似于这个函数的作用:
## combine both independent variables into one
df$condition = paste0(df$side, "_", df$color)
df$condition = as.factor(df$condition)
## calculate pairwise tests
mult_comp = df %>%
pairwise_t_test(
RT ~ condition, paired = TRUE,
p.adjust.method = "holm")%>%
select(-statistic, -df)
现在,问题是这个函数只能使用一个自变量(标准函数pairwise.t.test也是如此),而我实际上有两个自变量。
一种可能的解决方案是使用函数 aov 计算 ANOVA,然后使用函数 TukeyHSD 计算成对比较:
anova_df = aov(RT ~ side*color, data = df)
TukeyHSD(anova_df)
缺点是计算仅限于 Tukey 方法,这可能并不总是合适的。 此功能无法使用其他校正。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.