0

I know there are a lot of post about how to extract the p-value from an aov. However, I have a list with several thousand samples. i did an aov for each sample to compare two different treatments and now i am looking for a way to get a list with all the p-values, as i cannot copy them one by one..

is this even possible? I had no problems doing this for the p-values created by a ttest:

results <- apply(data,1,function(x){t.test(x[1:3],x[4:6])$p.value})

data is my imported .csv and [1:3] indicates the columns that are compared with the columns [4:6]

so that really was not a problem, but it seems not to be possible to do something similar for the aov:

results <- apply(data,1,function(x){aov(x[1:3]~x[4:6])})

i cannot get a list with all the p-values (that are called Pr(>F)..which is kind of frustrating.. hope you understand what i am trying to do,

csgillespie
  • 59,189
  • 14
  • 150
  • 185
soso
  • 11
  • 3

2 Answers2

0
results <- apply(data,1,function(x){anova(aov(x[1:3]~x[4:6]))[['Pr(>F)']][1]})
Russ Hyde
  • 2,154
  • 12
  • 21
  • i do hope you can help me once more: it works fine when i compare columns 1-3 with 4-6 but i cannot compare 1-3 with 7-8. Do i really need equal sizes? because i only have a duplicate of the last treatment.. – soso Jun 12 '14 at 14:12
  • 1
    I suspect you are doing your linear model incorrectly. You have three classes, the first two in triplicate and the last in duplicate. yu should really be using lm(x ~ as.factor(c(1,1,1,2,2,2,3,3))), or words to that effect. nonetheless, you won't be able to estimate the within class error for your final class. – Russ Hyde Jun 12 '14 at 16:02
  • so i cannot compare those treatment using anova as they have a different number of replicates? – soso Jun 12 '14 at 17:04
  • Not because they have a different number of replicates. Because you shouldn't try to estimate sd with so few samples. Try the lm code I just gave you, anova(lm(...)) will give you the analysis you need, but your CIs will be so wide as to make it pointless. Can't you just replicate your experiment/data acquisition? (and accept the answer if it solved your original problem) btw, elementary stats questions aren't stackoverflow material – Russ Hyde Jun 12 '14 at 21:39
0

Youll probably want lapply if the data is in a list already. And you can use summary to get the p-values from aov

lapply(yourData, function(x){
    av <- aov(yourFormula, data = x)
    summary(av)[[1]][,5]
})
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • well, apply is working..so does it make any difference to use lapply(regarding the results?) – soso Jun 12 '14 at 05:53
  • Generally, `apply` is used to apply a function to margins of an array or matrix, while `lapply` applies a function iteratively through a list. – Rich Scriven Jun 12 '14 at 06:17