How to compute a confidence interval for the population proportion (in R)
Task
If we have a sample of qualitative data from a normally distributed population, then how do we compute a confidence interval for a population proportion?
Related tasks:
- How to compute a confidence interval for a mean difference (matched pairs)
- How to compute a confidence interval for a regression coefficient
- How to compute a confidence interval for a population mean
- How to compute a confidence interval for a single population variance
- How to compute a confidence interval for the difference between two means when both population variances are known
- How to compute a confidence interval for the difference between two means when population variances are unknown
- How to compute a confidence interval for the difference between two proportions
- How to compute a confidence interval for the expected value of a response variable
- How to compute a confidence interval for the ratio of two population variances
Solution
We’re going to use some fake data here for illustrative purposes, but you can replace our fake data with your real data in the code below.
1
2
3
4
5
6
7
8
9
10
11
12
13
# Replace the next two lines of code with your real data
sample_size = 30
sample_proportion = 0.39
# Find the margin of error
alpha <- 0.05 # replace with your chosen alpha (here, a 95% confidence level)
moe <- qnorm(1-alpha/2, 0, 1) * sqrt(sample_proportion*(1-sample_proportion)/sample_size)
# Find the confidence interval
upper_bound <- sample_proportion + moe
lower_bound <- sample_proportion - moe
lower_bound
upper_bound
1
2
3
4
5
[1] 0.2154641
[1] 0.5645359
Our 95% confidence interval is $[0.2155, 0.5645]$.
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Contributed by Elizabeth Czarniak (CZARNIA_ELIZ@bentley.edu)