0

I'm conducting a simulation study in R. Basically, I generate fake data sets and then run an ANOVA on the data using the aov function. But I'm having difficulty extracting p-values. Previous questionss do not help (Extract p-value from aov) -- I am running a mixed ANOVA.

First I have an ANOVA:

results <- summary(aov(dv~(A*B*C*D*E)+Error(subj/(A*B*C*D)), data = mdata))  #  conduct repeated measures ANOVA

which generate this output:

Error: subj
      Df   Sum Sq Mean Sq F value Pr(>F)
E          1  1039157 1039157    0.95  0.334
Residuals 58 63428016 1093586               

Error: subj:A
      Df Sum Sq Mean Sq F value Pr(>F)
A          1   1996    1996   0.220  0.641
A:E        1   2294    2294   0.253  0.617
Residuals 58 526389    9076   

...

I'm truncating the output for space. What I want list of p-values with the effect name (A or A:E). I have halfway succeeded, but it's messy. I can extract the p-values using this get_p function that I made.

#Function
get_p = function(results,head){
  results[[1]]$'Pr(>F)'
}

#Get p-values
p <- sapply(results, get_p)

I end up with a this:

$`Error: subj`
[1] 0.3337094        NA

$`Error: subj:A`
[1] 0.6408826 0.6170181        NA

...

Any ideas on how to get a list of p-values (.6408, .6178) and effect names ('A', 'A:E')?

Community
  • 1
  • 1
Nick
  • 145
  • 2
  • 13

1 Answers1

0

I found the answer, which seems to be:

 get_p1 = function(results){
    results[[1]]$'Pr(>F)'[[1]]
 }
 get_p2 = function(results){
    results[[1]]$'Pr(>F)'[[2]]
 }
 pvals <- c(sapply(results, get_p1), sapply(results, get_p2))
Nick
  • 145
  • 2
  • 13