0

I am using this R- One way anova extracting p_value but failed...

So here is an over my code:

anova_sink<-c("a","b","c","d")
aov_result<-vector()
p_result<-vector()
for(i in 1:(length(anova_sink))){
  aov_result[i]<-aov(as.formula(paste("value","~",anova_sink[i])),df)
  p_result[i]<-tidy(aov_result[i])$p.value

}

This returned error

Error: No tidy method recognized for this list.

But according to

https://rdrr.io/cran/broom/man/tidy.aov.html

it should be fine.

I don't really know why...

To be honest, at this point, my problem is solved with Extract p-value from aov, however, I still want to know why the other method is failing.

Junyi Yao
  • 1
  • 1

1 Answers1

0

You need to use a double bracket (see this) to access the element of the list, so it should be:

tidy(aov_result[[i]])

and

aov_result[[i]]

So below is an example dataset:

set.seed(111)
df = data.frame(matrix(rnorm(100),ncol=5))
colnames(df) = c("a","b","c","d","value")

And we run your corrected code, note we get the first p.value from tidy() out:

anova_sink<-c("a","b","c","d")
aov_result<-vector("list",length(anova_sink))
p_result<-vector()
for(i in 1:(length(anova_sink))){
  aov_result[[i]]<-aov(as.formula(paste("value","~",anova_sink[i])),df)
  p_result[i]<-tidy(aov_result[[i]])$p.value[1]

}

p_result
[1] 0.95105366 0.00341931 0.48760857 0.95084692
StupidWolf
  • 45,075
  • 17
  • 40
  • 72