A binomial proportion has counts for two levels of a nominal variable. An example would be counts of students of only two genders, male and female. If there are 20 students in a class, and 12 are female, then the proportion of females are 12/20, or 0. 6, and the proportion of males are 8/20 or 0.4. This is a binomial proportion.
Gender Count Proportion
Female 12 0.60
Male 8 0.40
------ -- -----------
Total 20 1.00
A multinomial proportion has counts for more than two levels of a nominal variable. For example, we might have the following levels and counts for gender for students in a class:
Gender Count Proportion
Female 12 0.60
Male 6 0.30
Other 1 0.05
Prefer not to answer 1 0.05
-------------------- -- -----------
Total 20 1.00
Confidence intervals can be produced for either binomial or multinomial proportions.
The binom.test function in the native stats package will provide the Clopper-Pearson confidence interval for a binomial proportion. Other methods for a binomial proportion are provided by the BinomCI function in the DescTools package, as well as by various functions in the PropCIs package.
Confidence intervals for multinomial proportions can be produced with the MultinomCI function in the DescTools package.
Packages used in this chapter
The packages used in this chapter include:
• DescTools
• PropCIs
The following commands will install these packages if they are not already installed:
if(!require(DescTools)){install.packages("DescTools")}
if(!require(PropCIs)){install.packages("PropCIs")}
Example of confidence intervals for a binomial proportion
As part of a demographic survey of her scrapbooking 4-H course, Seras Victoria asks students if they have ever done scrapbooking before. The following are the data from her course:
Experience Count
Yes 7
No 14
---------- --
Total 21
Note that when calculating confidence intervals for a binomial variable, one level of the nominal variable is chosen to be the “success” level. This is an arbitrary decision, but you should be cautious to remember that the confidence interval is reported for the proportion of “success” responses. The BinomCI function in the DescTools package can produce the confidence interval for both “success” and “failure” in one step.
The binom.test function output includes a confidence interval for the proportion, and the proportion of “success” as a decimal number. The binom.test function uses the Clopper–Pearson method for confidence intervals.
### 7 is the count of sucesses, 21 is
the total count
binom.test(7, 21)
95 percent confidence interval:
0.1458769 0.5696755
sample estimates:
probability of success
0.3333333
The BinomCI function in the DescTools package has several methods for calculating confidence intervals for a binomial proportion.
library(DescTools)
BinomCI(7, 21,
conf.level = 0.95,
method = "clopper-pearson")
### Methods: "wilson",
"wald", "agresti-coull", "jeffreys",
### "modified wilson", "modified jeffreys",
### "clopper-pearson", "arcsine",
"logit", "witting", "pratt"
est lwr.ci upr.ci
[1,] 0.3333333 0.1458769 0.5696755
The BinomCI function in the DescTools package can also produce the confidence intervals for “success” and “failure” in one step.
### 7 is the count of sucesses and 14 is the count
of failures
library(DescTools)
observed = c(7, 14)
total = sum(observed)
BinomCI(observed, total,
conf.level = 0.95,
method = "clopper-pearson")
### Methods: "wilson",
"wald", "agresti-coull", "jeffreys",
### "modified wilson", "modified jeffreys",
### "clopper-pearson", "arcsine",
"logit", "witting", "pratt"
est lwr.ci upr.ci
[1,] 0.3333333 0.1458769 0.5696755
[2,] 0.6666667 0.4303245 0.8541231
The PropCIs package has functions for calculating confidence intervals for a binomial proportion.
The exactci function uses the Clopper–Pearson exact method.
7/21
[1] 0.3333333
library(PropCIs)
exactci(7, 21,
conf.level=0.95)
95 percent confidence interval:
0.1458769 0.5696755
The blakerci function uses the Blaker exact method.
7/21
[1] 0.3333333
library(PropCIs)
blakerci(7, 21,
conf.level=0.95)
95 percent confidence interval:
0.1523669 0.5510455
Example of confidence intervals for a multinomial proportion
As part of a demographic survey of her scrapbooking 4-H course, Seras Victoria asks students to report their gender. The following are the data from her course:
Gender Count
Female 10
Male 9
Other 1
No answer 1
---------- -----
Total 21
library(DescTools)
observed = c(10, 9, 1, 1)
MultinomCI(observed,
conf.level=0.95,
method="sisonglaz")
### Methods: "sisonglaz",
"cplus1", "goodman", "wald", "waldcc", "wilson", "qh", "fs"
est lwr.ci upr.ci
[1,] 0.47619048 0.2857143 0.7009460
[2,] 0.42857143 0.2380952 0.6533270
[3,] 0.04761905 0.0000000 0.2723746
[4,] 0.04761905 0.0000000 0.2723746
Optional analysis: confidence intervals for a difference in proportions
As part of a demographic survey of their scrapbooking 4-H courses, Seras Victoria and Integra Hellsing ask students if they have experience in scrapbooking. They want to determine the difference of proportions of students having experience in each class and calculate a confidence interval for that difference. The following are the data:
Seras Victoria Integra
Hellsing
Experience Count Experience Count
Yes 7 Yes 13
No 14 No 4
---------- ----- ---------- -----
Total 21 Total 17
Two functions in the PropCIs package can determine a confidence interval for a difference for in independent proportions.
7/21
[1] 0.3333333
13/17
[1] 0.7647059
(7/21) - (13/17)
[1] -0.4313725
library(PropCIs)
diffscoreci(7, 21, 13, 17,
conf.level=0.95)
95 percent confidence interval:
-0.6685985 -0.1103804
wald2ci(7, 21, 13, 17,
conf.level=0.95,
adjust = "Wald")
### adjust = "AC", "Wald"
95 percent confidence interval:
-0.7165199 -0.1462252
sample estimates:
[1] -0.4313725
References
“Confidence Limits” in Mangiafico, S.S. 2015a. An R Companion for the Handbook of Biological Statistics, version 1.09. rcompanion.org/rcompanion/c_04.html.