Docconcoct
Docconcoct

Reputation: 2050

Applying ezANOVA error work-around to Long Format data

I have a similar problem as described here:

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

Here is an example of what my dataframe looks like:

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

I have 3 Visual conditions, 5 Audio conditions & 5 StimConditions & 12 participants exposed to all conditions.

When I run the following ezANOVA:

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

I get the same error as the linked question above. I have tried changing Type to equal 1 and it does return the output but minus the Sphericity Test.

I've tried to apply the solution to the linked question to my dataset but as mine is in Long Format I'm a bit lost as to what exactly I need to do to achieve the desired stats.

I'll keep playing with it my end but if anyone could help in the mean time it would be much appreciated.

Thanks.

Upvotes: 1

Views: 642

Answers (1)

cdeterman
cdeterman

Reputation: 19970

Following the linked question, you have don't have to change much. Assuming your dataset is exactly as you describe, the following should work for you.

Let's first create a dataset to reflect your description

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)

Now we have a dataframe with 3 Visual conditions, 5 Audio conditions & 5 StimConditions & 12 participants exposed to all conditions. This should be at the stage you are currently at. We can do the between-subjects call easily.

# 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)

For the factor component, this is the only real change. If you simply generate your model design, you can pass it to 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...

Upvotes: 3

Related Questions