1
$\begingroup$

I am trying to do a repeated measures ANOVA on unstacked data for my experiment. For background, my experimental design is as follows: I have 160 stimuli divided evenly into 8 counterbalanced list, each stimulus is labelled as a condition (1-8). The participant was exposed to 1 list (20 stimuli) and I recorded their Reaction times to a button press. I have 40 participants in total. My independent variable is the condition of a stimulus (1-8) and my dependent variable is the recorded reaction time.

Here is what my data looks like, its the averages per condition per participant in seconds:

participant con1.pdd con2.dpp con3.ddd con4.pdp con5.ppd con6.dpp con7.dpd con8.ppp
        1    0,717    0,724    0,526    0,501    0,673    0,733    0,55     0,442
        2    0,522    0,434    0,622    0,501    0,409    0,267    0,848    0,549
        3    0,584    0,226    0,643    0,273    0,494    0,422    0,367    0,251
        ...
        38   0,524    0,327    0,434    0,524    0,42     0,2      0,493    0,408 
        39   0,413    0,491    0,303    0,491    0,567    0,487    0,353    0,453
        40   0,379    0,32     0,274    0,262    0,227    0,37     0,221    0,229

This is how I have been told my data should look like when performing a repeated measures ANOVA. However when looking at the R function that performs a repeated measures ANOVA, it does not seem like I am on the right track. R formula with the variables in brackets:

 aov([dependentvar] ~ [independentvar] + Error(Participant_ID/[dependentvar]), data=[dataframe])

I dont seem to be able to perform an ANOVA using this function, since my dependent variable is not gathered under 1 column. I am starting to get a bit lost here. Can I still perform a RM-anova with my data?

My apologies for not asking a very concise question, I hope I explained my problem properly.

$\endgroup$

1 Answer 1

1
$\begingroup$

The easiest way is to convert your dataframe from a wide format to a long format and then pass that to the aov function. The tidyr package has the function gather for just such conversion.

so<-read.table(header = TRUE, text="participant con1.pdd con2.dpp con3.ddd con4.pdp con5.ppd con6.dpp con7.dpd con8.ppp
1    0.717    0.724    0.526    0.501    0.673    0.733    0.55     0.442
2    0.522    0.434    0.622    0.501    0.409    0.267    0.848    0.549
3    0.584    0.226    0.643    0.273    0.494    0.422    0.367    0.251
38   0.524    0.327    0.434    0.524    0.42     0.2      0.493    0.408 
39   0.413    0.491    0.303    0.491    0.567    0.487    0.353    0.453
40   0.379    0.32     0.274    0.262    0.227    0.37     0.221    0.229")

library(tidyr)
#convert from wide to long 
so2<-gather(so, key="key", value = "value", 2:9 )
#run aov on the new datafrom
aov(value ~ key+participant , data=so2)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.