8 Chi-squared Test
Let’s say a drug company is interested in evaluating the performance of two new drugs in development, New Drug 1 (D1) and New Drug 2 (D2), in alleviating Disease Y symptoms. They want to test it against the current standard drug (ST). They enroll 1000 people in a large clinical trial, and found that:
- out of the 400 people put on D1, 200 found their health status improve,
- out of the 200 people put on D2, 150 found their health status improve, and
- out of the 400 people put on ST, 240 found their health status improve.
You can create the table directly in R:
drug <- matrix(c(200, 200, 150, 50, 240, 160), ncol = 2, byrow = TRUE)
colnames(drug) <- c("Improved", "NotImproved")
rownames(drug) <- c("D1", "D2", "ST")
#drug <- as.table(drug)
drug
## Improved NotImproved
## D1 200 200
## D2 150 50
## ST 240 160
We can test for dependence between the row and column variables, using Pearson’s chi-squared test. We can perform the chi-squared test very easily using the chisq.test()
function.
chisq.test(drug)
##
## Pearson's Chi-squared test
##
## data: drug
## X-squared = 34.725, df = 2, p-value = 2.881e-08
We can also access the expected counts that chisq.test()
calculates automatically.
chisq.test(drug)$expected
## Improved NotImproved
## D1 236 164
## D2 118 82
## ST 236 164