Proportion test in R
How to do a proportion test in R and what are the conditions need to met for proportion test?
- The sampling method for each population is simple random sampling.
- The samples are independent.
- Each sample includes at least 10 successes and 10 failures.
- Each population is at least 20 times as big as its sample.
The proportions test is used to compare two observed proportions or single sample observations. This article describes the basics of proportions analysis in R.
In statistics, we can define the corresponding null hypothesis (H0) as follow:
The corresponding alternative hypotheses (Ha) are as follow:
- Ha:pA≠pB (different)
- Ha:pA>pB (greater)
- Ha:pA<pB (lesser)
1 is two-tailed tests and 2 & 3 are one tailed test.
R functions prop.test() can be used for calculating proportion significance.
The One-Sample Proportion Test is used to assess whether a population proportion (P1) is significantly different
from a hypothesized value (P0). This is called the hypothesis of inequality. The hypotheses may be stated in terms
of the proportions, their difference, their ratio, or their odds ratio, but all four hypotheses result in the same test statistics.
prop.test(x,n,p=NULL, alternative = “two.sided”, correct = TRUE)
prop.test(x = c(490, 400), n = c(500, 500))
one sided test
prop.test(x = c(400, 350), n = c(500, 500), alternative = “less”)
prop.test(x = c(400, 350), n = c(500, 500), alternative = “greater”)
The p-value of the test which is less than the significance level alpha = 0.05. We can conclude that the proportion of samples is significantly different in the two groups with a p-value = 0.0001728.