Andrey Bombin
Andrey Bombin

Reputation: 49

How to extract p values from a vector with multiple anova

Using R, I created a vector with 39 anovas using the following script

w3<-lapply(split(q1, q1$taxa), aov, formula=trig ~ d)

I can extract p values from each of them separately via summary(w3$"type") but how can I do it for all 39 at once, preferably writing all the p values in a separate data frame?

Also, it is possible to create a list with a summary for each individual anova with

e7<-lapply(w3, FUN=summary) 

but is there a way to make a data frame with p values from this list?

Upvotes: 1

Views: 503

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388797

You can use sapply to iterate over each anova and extract p-value.

sapply(w3, function(x) summary(x)[[1]][["Pr(>F)"]][[1]])

Using reproducible example with mtcars

w3 <- lapply(split(mtcars, mtcars$cyl), aov, formula=mpg ~ am) 
sapply(w3, function(x) summary(x)[[1]][["Pr(>F)"]][[1]])

#     4      6      8 
#0.0892 0.2209 0.8662 

Upvotes: 1

Related Questions