How to find 95% confidence interval for binomial data in R?


The binomial data has two parameters, the sample size and the number of successes. To find the 95% confidence interval we just need to use prop.test function in R but we need to make sure that we put correct argument to FALSE so that the confidence interval will be calculated without continuity correction. In the below examples, we have found the 95% confidence interval for different values of sample size and number of successes.

Example

 Live Demo

prop.test(x=25,n=100,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 25 out of 100, null probability 0.5
X-squared = 25, df = 1, p-value = 5.733e-07
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.1754521 0.3430446
sample estimates:
p
0.25

Example

 Live Demo

prop.test(x=5,n=100,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 5 out of 100, null probability 0.5
X-squared = 81, df = 1, p-value < 2.2e-16
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.02154368 0.11175047
sample estimates:
p
0.05

Example

 Live Demo

prop.test(x=5,n=1000,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 5 out of 1000, null probability 0.5
X-squared = 980.1, df = 1, p-value < 2.2e-16
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.002137536 0.011650955
sample estimates:
p
0.005

Example

 Live Demo

prop.test(x=5,n=10,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 5 out of 1000, null probability 0.5
X-squared = 980.1, df = 1, p-value < 2.2e-16
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.002137536 0.011650955
sample estimates:
p
0.005

Example

 Live Demo

prop.test(x=50,n=100,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 50 out of 100, null probability 0.5
X-squared = 0, df = 1, p-value = 1
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.4038315 0.5961685
sample estimates:
 p
 0.5

Example

 Live Demo

prop.test(x=500,n=1125,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 500 out of 1125, null probability 0.5
X-squared = 13.889, df = 1, p-value = 0.0001939
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.4156458 0.4736212
sample estimates:
 p
 0.4444444

Example

 Live Demo

prop.test(x=5000,n=9874,conf.level=0.95,correct=FALSE)

Output

1-sample proportions test without continuity correction
data: 5000 out of 9874, null probability 0.5
X-squared = 1.6079, df = 1, p-value = 0.2048
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.4965185 0.5162373
sample estimates:
p
0.5063804

Updated on: 10-Oct-2020

545 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements