This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ANOVA for several variables + model validation in R

I am interested in comparing different concentrations of lipids between 3 treatment groups. For each lipid I want to use the lm function and a one-way ANOVA, but in this case I have hundreds of lipids.

Based on what I have read in this forum, I should be able to use this code to run the same model for all lipids:

mydata %>%
nest(data = c(Treatment, Value)) %>% 
mutate(model = map(data, ~anova(lm(Value ~ Treatment, .))), tidy = map(model, broom::tidy)) %>% 
select(Lipid, tidy) %>% 
unnest(tidy)

However, I am getting an error message for "unnest(tidy)":

`contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

What am I doing wrong?

And how do I include model validation in this?

My data looks similar to this:

Treatment     Lipid     Value
       A               1          5.0
       A               2          1.2
       A               3          3.0
       B               1          6.2
       B               2          1.5
       B               3          4.5
       C               1          4.9
       C               2          2.3
       C               3          1.0
r anova statistics

0 answers

No answers yet.

Log in to answer this question.