To perform a hypothesis test for a single proportion you need to use the prop.test()
function and specify the number of successes, x
, the sample size, n
, the value of the population proportion, p
, 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 = successes, n = sample.size, p = population.p, alternative="less", 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, x
, the sample size, n
, 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 = successes, n = sample.size, correct=FALSE)$conf.int
Suppose you were investigating whether or not a coin was a fair coin. You flipped the coin 715 times and found that the coin came up heads 319 times.
prop.test(x = 319, n = 715, p=.5, alternative = "two.sided", conf.level=.95, correct=FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: 319 out of 715, null probability 0.5
## X-squared = 8.2923, df = 1, p-value = 0.003981
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.4101018 0.4827814
## sample estimates:
## p
## 0.4461538
Mathematicss, Computer Science, and Statistics Department Gustavus Adolphus College