0

I have the following loop which lets me do repeated measures ANOVA, to analyse if there is a significant difference between 1 mean rating (named Anger here) against 8 other mean ratings (the 8 different emotions in the list) in a musical track.

As it is a repeated measures ANOVA, I am aware that a p-value correction has to be made, hence I would like to do a Bonferroni adjustment. However, I am not sure how to write it for this particular code and where it should be placed in the loop.

CODE:

trk <- fltr[fltr$Track == '001',]
lst <- c('Joy','Calm','Fear','Longing','Love','Power','Sad','Surprise')

for(k in 1:8){
    trgt <- trk[trk$Emotion == 'Anger',]  
    other <- trk[trk$Emotion == lst[k],]
    trgt <- rbind(trgt,other)  
    cat('Anger vs.', lst[k],'\n')  
    print(summary(aov(Rating ~ Emotion + Error(participant/Emotion),trgt))) 
    cat('\n')
}

Any help would be appreciated.

Thank you.

bcperth
  • 2,191
  • 1
  • 10
  • 16
AMG
  • 1
  • 2
  • The p-value might be part of the aov object. Applying the Bonferroni correction might be easiest if you explicitly saved (or appended to a vector, in a for loop) the respective p-values as a separate data structure – 12b345b6b78 Oct 19 '18 at 14:41
  • @12b345b6b78 thank you for the explanation. I thought I could add a line of code in the same loop. I'll look into doing another for loop to calculate the p-value adjustment. Thanks once again. – AMG Oct 20 '18 at 10:14
  • You might be able to! If I'm understanding things correctly, nothing's preventing you from initializing an empty vector before the for loop and `c()`'ing the p-values to it with every iteration of the loop – 12b345b6b78 Oct 20 '18 at 15:25
  • @12b345b6b78 sorry for asking so many questions, but how would one extract the p-values from the aov()? As in, how can you 'call them out'? As $___ would not work. Apologies, but I'm new to R and some things I can't seem to figure out. Thank you. – AMG Oct 21 '18 at 10:28
  • Don't worry! And to answer your question, I thought p-values were part of the aov object, but after finding this answer: https://stackoverflow.com/questions/3366506/extract-p-value-from-aov I realized they're actually part of what the `summary()` function/method returns when evaluating an aov object. So, in your case, it would be `summary(aov)[[1]][['Pr(>F)']]` – 12b345b6b78 Oct 21 '18 at 17:18
  • @12b345b6b78 thank you so much for all your help!! It means a lot! – AMG Oct 22 '18 at 09:58

0 Answers0