ANOVA for several variables + model validation in R
0
0
Entering edit mode
4.0 years ago
nicole • 0

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 • 652 views
ADD COMMENT

Login before adding your answer.

Traffic: 3197 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6