Introduction
You might already be aware of an independent samples t-test or a matched-pairs t-test as approaches to comparing the means of continuous variables. In this post, we’ll show you how to compare proportions, rather than means, using R’s prop.test command.
Create Data and Run Proportions Test
Let’s say you want to compare consumer preferences for two products, A and B. You ask 310 people if they would definitely buy A, and you ask 299 people if they would definitely buy B. You find that 112 people definitely want to buy A, and 86 people definitely want to buy B. You have a two-tailed hypothesis structure, such that:
H0: Proportion of A = proportion of B
HA: Proportion of A ≠ proportion of B
Now try the following code in R:
prop.test(x = c(112, 86), n = c(310, 299))
Here’s what you get:
R gives you the proportions and a 2-sided p value, which, as you can see, is not significant at p < .05. Remember, if you wanted to use a one-tailed hypothesis testing structure such that:
H0: Proportion of A ≤ proportion of B
HA: Proportion of A > proportion of B
You could manually halve the two-tailed p value R gives you here, or could try this new code:
prop.test(x = c(112, 86), n = c(310, 299), alternative = "greater")
You could also have had the following hypothesis structure:
H0: Proportion of A ≥ proportion of B
HA: Proportion of A < proportion of B
In which case, you could have tried:
prop.test(x = c(112, 86), n = c(310, 299), alternative = "less")
Notice that the choice of "less" or "greater" in the code is governed by the direction of the inequality in the alternative hypothesis.
BridgeText can help you with all of your statistical analysis needs.