I am struggling with choosing the appropriate statistical analysis for a dataset in which there are multiple groups (groupA-groupE), each having a certain number of counts in two categories (healthy or sick) that can also be presented as a proportion (sick/[sick+healthy]):
df <- data.frame(group = c("groupA","groupB","groupC","groupD","groupE"),
n_sick = c(12, 32, 99, 37, 48),
n_healthy = c(36, 250, 120, 68, 93))
df %<>% mutate(tot = n_sick + n_healthy, prop = n_sick / tot)
I would like to find out which groups have statistically different proportions from each other, akin to what one would do in e.g. ANOVA/Kruskal-Wallis+post-hoc tests when there are replicates. However, the only available data in this case is the number of sick and healthy individuals per group. I understand the I can use the Chi-square test to uncover if there is a relationship between proportion and group
, but to my knowledge there are no standardized post-hoc tests for testing intergroup differences (correct me if I'm wrong!).
I found that the stats
package contains a function called pairwise_prop_test
that looks as though it does what I want it to do:
t <- as.table(rbind(
c(12, 32, 99, 37, 48),
c(36, 250, 120, 68, 93)))
dimnames(t) <- list(
condition = c("n_sick", "n_healthy"),
group = c("groupA","groupB","groupC","groupD","groupE"))
pairwise_prop_test(t, p.adjust.method = "bonferroni")
... which spits out a p.adj value for each comparison between groups (e.g. groupB differs from groupC). Is this the correct approach to take, or am I overlooking something? Thank you for taking the time to help!