phe_proportion {PHEindicatormethods} | R Documentation |
Calculate Proportions using phe_proportion
Description
Calculates proportions with confidence limits using Wilson Score method (1,2).
Usage
phe_proportion(data, x, n, type = "full", confidence = 0.95, multiplier = 1)
Arguments
data |
a data.frame containing the data to calculate proportions for, pre-grouped if proportions required for group aggregates; unquoted string; no default |
x |
field name from data containing the observed numbers of cases in the sample meeting the required condition (the numerator for the proportion); unquoted string; no default |
n |
field name from data containing the number of cases in the sample (the denominator for the proportion); unquoted string; no default |
type |
defines the data and metadata columns to be included in output; can be "value", "lower", "upper", "standard" (for all data) or "full" (for all data and metadata); quoted string; default = "full" |
confidence |
the required level of confidence expressed as a number between 0.9 and 1 or a number between 90 and 100. The vector c(0.95, 0.998) can also be passed to output both 95 percent and 99.8 percent CIs, or an NA value can be passed if no confidence intervals are required.; numeric; default 0.95 |
multiplier |
the multiplier used to express the final values (eg 100 = percentage); numeric; default 1 |
Value
When type = "full", returns the original data.frame with the following appended: proportion, lower confidence limit, upper confidence limit, confidence level, statistic and method
Notes
Wilson Score method (2) is applied using the internal wilson_lower
and wilson_upper functions.
The percentage argument was deprecated in v1_1_0, please use multiplier argument instead
References
(1) Wilson EB. Probable inference, the law of succession, and statistical
inference. J Am Stat Assoc; 1927; 22. Pg 209 to 212.
(2) Newcombe RG, Altman DG. Proportions and their differences. In Altman
DG et al. (eds). Statistics with confidence (2nd edn). London: BMJ Books;
2000. Pg 46 to 48.
See Also
Other PHEindicatormethods package functions:
assign_funnel_significance()
,
calculate_ISRate()
,
calculate_ISRatio()
,
calculate_funnel_limits()
,
calculate_funnel_points()
,
phe_dsr()
,
phe_life_expectancy()
,
phe_mean()
,
phe_quantile()
,
phe_rate()
,
phe_sii()
Examples
# ungrouped data frame
df <- data.frame(area = rep(c("Area1","Area2","Area3","Area4"), each=3),
numerator = c(NA,82,9,48, 6500,8200,10000,10000,8,7,750,900),
denominator = rep(c(100,10000,10000,10000), each=3))
phe_proportion(df, numerator, denominator)
phe_proportion(df, numerator, denominator, confidence=99.8)
phe_proportion(df, numerator, denominator, type="standard")
phe_proportion(df, numerator, denominator, confidence = c(0.95, 0.998))
# grouped data frame
library(dplyr)
dfg <- df |> group_by(area)
phe_proportion(dfg, numerator, denominator, multiplier=100)