Comparing means is not the only way to compare two samples. Here is an example where proportions or rates may be used to compare groups. Let’ssee that with a quick example:
You run an experiment where mice dispatched in 2 groups (a control group and an experimental group) are tested for their capacity to escape from a maze in a given amount of time. You carefully note the number of successes for each group and end up with the following results: 5 mice (out of 20) from group A made it in time whereas 9 mice (out of 27) from group B made it in time.
The “success rates” in group A and B being 25% and 33% respectively, it looks like the mice in group B performed better in this test. But did this result happen by chance? What if we do this test again and again…? How likely is it that group B performs better, again?
The function prop.test(x, y)
runs a test for equality of proportions. It compares the proportions or probabilities of success, the null hypothesis H0
stating that these proportions are equal. x
is a vector that contains the number of success for each group and y
is a vector that contains the total numbers of individuals in each group).
Let’s run this test on our example.
x <- c(5,9)
y <- c(20,27)
prop.test(x, y)
##
## 2-sample test for equality of proportions with continuity
## correction
##
## data: x out of y
## X-squared = 0.087084, df = 1, p-value = 0.7679
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## -0.3869107 0.2202441
## sample estimates:
## prop 1 prop 2
## 0.2500000 0.3333333
Looking at the test output, you can see that the obtained p-value is quite high. The null hypothesis is thus accepted. The apparent difference in success rate between group A and group B is likely to have occurred only by chance. Mice in group B are not faster or more clever than in group A, based on this test.