| prop.ci | R Documentation |
Provide a convenient wrapper for prop.test to compute
confidence intervals for proportions
prop.ci(x, n = NULL, bounds = 1:2, ...)
prop.ci.lower(x, n = NULL, ...)
prop.ci.upper(x, n = NULL, ...)
x |
a factor vector, a logical vector, a one-dimensional table or a vector of
count of successes (in that case, |
n |
a vector of count of trials ( |
bounds |
|
... |
additional parameters used by |
prop.ci.lower is a wrapper for prop.ci with bounds = 1 and
prop.ci.upper for prop.ci with bounds = 2.
When x and n are provided, they should be of same length. Alternativaly,
n could be a single integer that will be used for each element of x.
When x and n are provided, if x contains several elements,
bounds should be 1 or 2 but can't be 1:2. In that scenario,
the returned vector will contain the corresponding lower or the upper confidence interval
bound for each element of x.
The confidence level could be specify with conf.level (0.95 by default).
By default, NA value are removed.
a vector with confidence interval
prop.test
if (require(questionr)) {
data(hdv2003)
d <- hdv2003
freq(d$sport)
prop.ci(d$sport)
prop.ci.lower(d$sport)
prop.ci.upper(d$sport)
prop.ci(d$sport, conf.level = 0.9)
prop.ci(table(d$sport))
prop.ci(d$sport == "Non")
prop.ci(d$sport == "Oui")
prop.ci.lower(c(1277, 723), n = 2000)
prop.ci.upper(c(1277, 723), n = 2000)
if (require(data.table)) {
d <- as.data.table(d)
res <- d[, .(freq = .N), by = .(sexe, sport)]
res[, n := sum(freq), by = sexe]
res[, prop := freq / n]
res[, prop.l := prop.ci.lower(freq, n)]
res[, prop.h := prop.ci.upper(freq, n)]
res
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.