your budget wasnt numeric so i had to alter that. and strictness has become strictself.
library(tidyverse)
library(broom) # tidy models
library(purrr) # iteration
example <- tibble::tribble(
~size, ~budget, ~strictself,
"Small", "11,718183", 1L,
"Medium", "5,264815", 2L,
"Large", "-0,43848", NA,
"Small", "0,658158", 2L,
"Medium", "-1,2867", 3L,
"Large", "-0,8482", 2L,
"Small", "4,584138", 1L,
"Medium", "7,26868", 1L,
"Large", "-7,1868", NA,
"Small", "8,186884", 1L,
"Medium", "16,1548", NA,
"Large", "1,516844", 2L,
"Small", "-5,1687", 2L,
"Medium", "11,15687", 2L,
"Large", "-4,1867", 3L,
"Small", "7,25687", 3L,
"Medium", "5,1682186", 1L,
"Large", "-6,186515", 2L,
"Small", "7,2687", 3L
) %>% mutate(budget = parse_number(budget))
(size_strict_summary <- example %>%
group_by(size, strictself) %>%
summarise(mean = mean(budget, na.rm = TRUE),
sd = sd(budget, na.rm = TRUE),
n = n()) %>%
filter(!is.na(strictself)))
(krusjal_tests <- map_dfr(
unique(size_strict_summary$size),
~ mutate(kruskal.test(budget ~ strictself,
data = filter(example, size == .)) %>% tidy(),
esub = .
) %>% select(esub, everything())
))
(pairwilcox_tests <- map_dfr(
unique(size_strict_summary$size),
~ mutate(pairwise.wilcox.test(filter(example, size == .)[["budget"]],
filter(example, size == .)[["strictself"]],
p.adjust.method = "BH"
) %>% tidy(),
esub = .
) %>% select(esub, everything())
))