Big Picture:
How can I implement partitioned Chi Square in R? I understand how to perform the overall Chi square, and then how to get individual parameters (observed counts, expected counts, residuals, etc.). However, I don't understand how to get p values for each individual comparison.
Details:
set.seed(200)
alpha = 0.05
I have three groups of patients and I have both categorical and continuous data collected on those patients.
Group <- c(rep('A', 'B', 'C'), 10))
Mass <- c(rnorm(10, mean = 60, sd = 1),
rnorm(10, mean = 70, sd = 1),
rnorm(10, mean = 80, sd = 1))
Sex <- rep(c('Male', 'Female'), 15)
data <- data.frame(Group, Mass, Sex)
I'd like to construct your basic "Table 1" showing whether these groups differ from one another with respect to these variables.
For the continuous variables, I would do an anova test. If p were less than alpha, I would do individual t.tests and interpret my p values using a Bonferroni correction.
print('Anova p-value:')
print(anova(lm(Mass ~ Group, data))$'Pr(>F)'[1])
print(t.test(Mass ~ Group, data[data$Group != 'A',])$p.value)
print(t.test(Mass ~ Group, data[data$Group != 'B',])$p.value)
print(t.test(Mass ~ Group, data[data$Group != 'C',])$p.value)
I'd like an analogous output for my discrete variables. I know that I can do a Chi square test on the data as a whole...
print(chisq.test(x = data$Group, y = data$Sex)[['p.value']])
...but I'm confused about the correct way to get and interpret individual p values. I found this question, which links to a powerpoint about "partitioning" the chi square test, but I'm having trouble following it.