I've got a data frame featuring participants belonging to one of four cohorts (a,b,c, and d). Every participant was asked about their gender (1=female, 2=male, 3= don't want to answer).
How do I compare the proportion of eg females in the different cohorts (a, b, c, and d)?
I've tried a chi-square test (see below) but I'm not sure about this. I'm interested in the proportion of eg females, and it seems to me I haven't in any way factored in the size of the cohorts.
Any help would be much appreciated!
# Prep data gender<-floor(runif(240, min=1, max=4)) data_cohort<-rep(c("a", "b","b", "c","d"), 48) df<-data.frame(data_cohort,gender) # Get summary stats library(dplyr) df2 <- df %>% group_by(data_cohort,gender) %>% summarise (n = n()) %>% mutate(freq = round((n / sum(n)),2)) df2 <- as.data.frame(df2) # Run test to compare the proportion of females (gender == 1) in the cohorts myvec <- df2[df2$gender == 1, "n"] chisq.test(myvec)