【问题标题】:Applying ezANOVA error work-around to Long Format data将 ezANOVA 错误解决方法应用于长格式数据
【发布时间】:2026-02-08 13:15:01
【问题描述】:

我遇到了与此处所述类似的问题:

https://stats.stackexchange.com/questions/58435/repeated-measures-error-in-r-ezanova-using-more-levels-than-subjects-balanced-d

这是我的数据框的示例:

Participant  Visual             Audio              StimCondition    Accuracy

1            Bottom Circle 1st  2 Central Beeps    AO2              0.92

1            SIM Circle         Left Beep          AO2              0.86

2            Bottom Circle 1st  2 Central Beeps    CT4              0.12

2            SIM Circle         Left Beep          CT4              0.56

我有 3 种视觉条件、5 种音频条件和 5 种刺激条件以及 12 名参与者暴露于所有条件。

当我运行以下 ezANOVA 时:

Model <- ezANOVA(data = Shaped.means, dv = .(Accuracy), wid = .(Participant), within = .(Visual, Audio, StimCondition), type = 3, detailed = TRUE)

我收到与上面链接的问题相同的错误。我尝试将 Type 更改为等于 1,它确实返回了输出,但减去了 Sphericity Test。

我已尝试将链接问题的解决方案应用于我的数据集,但由于我的格式为长格式,我有点迷茫我究竟需要做什么才能获得所需的统计数据。

我将继续使用它,但如果有人能在此期间提供帮助,将不胜感激。

谢谢。

【问题讨论】:

  • 澄清一下:您的数据是宽格式还是长格式?您提供的示例数据表明它采用宽格式,但您稍后指出它采用长格式...
  • 您好,数据为长格式。例如,Visual 下面的值是不同的变量。例如:“SIM Circle”是指同时呈现2个圆圈;而“底圈1st”是指底圈显示在顶圈之前。 Audio & StimCondition 列也是如此,其中每个名称都引用一个变量。

标签: r anova


【解决方案1】:

按照链接的问题,您不必进行太多更改。假设您的数据集与您描述的完全一样,以下内容应该适合您。

让我们首先创建一个数据集来反映您的描述

set.seed(123)  ## make reproducible
N  <- 12       ## number of Participants
S  <- 5        ## number of StimCondition groups
V  <- 3       ## number of Visual groups
A <- 5    ## number of Audio groups
Accuracy <- abs(round(runif(N*V*S*A), 2))   ## (N x (PxQ))-matrix with voltages

init.Df <- expand.grid(Participant=gl(N,1),
                                Visual=gl(V, 1), 
                                Audio=gl(A, 1), 
                                StimCondition=gl(S,1))

df <- cbind(init.Df, Accuracy)

现在我们有一个数据框,其中包含 3 个视觉条件、5 个音频条件和 5 个刺激条件以及 12 个暴露于所有条件的参与者。这应该是你目前所处的阶段。我们可以轻松地进行主体间调用。

# If you just read in the data set and don't know how many subjects
# N <- length(unique(df$Participant))
fit <- lm(matrix(df[,c("Accuracy")], nrow=N) ~ 1)

对于因子组件,这是唯一真正的变化。如果您只是生成模型设计,可以将其传递给anova

library(car)
# You can create your within design table
# You can get these values from your dataset as well
# V <- nlevels(df$Visual)
# A <- nlevels(df$Audio)
# S <- nlevels(df$StimCondition)
# If you want the labels with gl, you can use the levels function (e.g. labels=levels(df$Visual))
inDf <- expand.grid(Visual=gl(V, 1), 
                    Audio=gl(A, 1), 
                    StimCondition=gl(S,1)) 

# Test for Visual
anova(fit, M=~Visual, X=~1, idata=inDf, test="Spherical")

# Test for Audio
anova(fit, M=~Visual+Audio, X=~Visual, idata=inDf, test="Spherical")

# Test for Visual:Audio interaction
anova(fit, M=~Visual+Audio+Visual:Audio, X=~Visual+Audio, idata=inDf, test="Spherical")

#etc...

【讨论】:

    最近更新 更多