Reputation: 3
I have several samples which were measured twice daily for 20 days in the format:
sample, concentration, day, replicate
How do I get the nested anova for each sample using the below function?
nest <- aov(concentration ~ day / factor(replicate))
How would I run a nested anova for each "plant_type" without creating 8 subsets?
Upvotes: 0
Views: 721
Reputation: 8826
If I understood correctly, this example might help you
library(tidyverse)
library(broom)
mtcars %>%
# Create 2 factors variables
mutate(
gear = as.factor(gear),
cyl = as.factor(cyl)
) %>%
# Group and nest data by each level of gear
group_nest(gear) %>%
mutate(
# Apply ANOVA por each level of gear, for drat~cyl
anova = map(.x = data,.f = ~anova(aov(drat~cyl,data = .x))),
# Get results of ANOVA
results = map(anova,tidy)
) %>%
# "Show" the results for each gear level
unnest(results)
# A tibble: 6 x 9
gear data anova term df sumsq meansq statistic p.value
<fct> <list<tibble[,10]>> <list> <chr> <int> <dbl> <dbl> <dbl> <dbl>
1 3 [15 x 10] <anova [2 x 5]> cyl 2 0.414 0.207 3.91 0.0491
2 3 [15 x 10] <anova [2 x 5]> Residuals 12 0.634 0.0529 NA NA
3 4 [12 x 10] <anova [2 x 5]> cyl 1 0.107 0.107 1.10 0.318
4 4 [12 x 10] <anova [2 x 5]> Residuals 10 0.967 0.0967 NA NA
5 5 [5 x 10] <anova [2 x 5]> cyl 2 0.158 0.0790 0.352 0.740
6 5 [5 x 10] <anova [2 x 5]> Residuals 2 0.449 0.225 NA NA
Upvotes: 0