To perform a hypothesis test for a single proportion you need to use the prop.test()
function and specify the number of successes in each group, x = c(x1, x2)
, the sample size of each group, n = c(n1, n2)
, the value of the population proportion, correct = FALSE
, and the alternative hypothesis. By default the alternative hypothesis is "two.sided", but you can also use "less", or "greater".
You can calculate the z test statistic by taking the square root of the "X squared" statistic in the output. You need not modify the p-value.
prop.test(x = c(x1, x2), n = c(n1, n2), alternative="two.sided", correct=FALSE)
To calculate a confidence interval for a single proportion you need to use the prop.test()
function and specify the number of successes in each group, x = c(x1, x2)
, the sample size of each group, n = c(n1, n2)
, set the confidence level, conf.level = .95
, and set correct = FALSE
. Adding $conf.int
to the end of the prop.test()
function will display only the confidence interval.
prop.test(x = c(x1, x2), n = c(n1, n2), correct=FALSE)$conf.int
Suppose you interviewed 300 men and 400 women and recorded their eye color. 179 of the men and 203 of the women had blue eyes. Is there a significant difference in the proportion of blue eyed men and women?
prop.test(x = c(179, 203), n = c(300, 400), alternative = "two.sided", conf.level=.95, correct=FALSE)
##
## 2-sample test for equality of proportions without continuity correction
##
## data: c(179, 203) out of c(300, 400)
## X-squared = 5.4979, df = 1, p-value = 0.01904
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## 0.01512659 0.16320674
## sample estimates:
## prop 1 prop 2
## 0.5966667 0.5075000
Mathematicss, Computer Science, and Statistics Department Gustavus Adolphus College