grprr
Rates and proportions by group: ratios and differences
grprr( x, n = NULL, grp = NULL, ref = NULL, type = "rate", per = 1, level = 0.95)The rate (events over exposure) or the proportion (events over trials)
of each group, and its ratio to and difference from a reference group,
with approximate and exact intervals. Rows that share a group are
pooled: give one row per group, or one per case (0/1 outcomes with
n = 1, the default for proportions), or anything between.
Parameters
Section titled “Parameters”xThe events: numbers from 0; or a
clprelist fromclprep().nThe exposure (person-time, population) of each row for rates, or the trials for proportions: positive numbers;
NULLfor one trial per row (proportions only).grpNULL(each row is a group, named by the names ofx) or the group of each row: labels.refThe reference group: a label or a position; the first group by default.
type"rate"(events over exposure) or"prop"(a proportion).perThe rates and differences are given per
perunits ofn(1e5 for rates per 100,000, 100 for percentages): one positive number.levelThe confidence level of the intervals: one number strictly between 0 and 1.
Returns
Section titled “Returns”An object of class grprr, a list: rates, a data frame with
one row per group (group, x, n, rate, lo, hi the
approximate interval, elo, ehi the exact one, rep); cmp, one
row per group but the reference (group, ratio, lo, hi, elo,
ehi, diff, dlo, dhi); ref, type, per and level.
For a rate x / n the approximate interval is rate * exp(-+z / sqrt(x)) and the exact one the Poisson interval through the gamma
quantiles, as stats::poisson.test(); the ratio’s approximate interval
is log-normal with variance 1 / x + 1 / x0, its exact interval the
one conditional on the total count (the Clopper-Pearson interval of x / (x + x0), as the two-sample stats::poisson.test()), and the
difference’s is Wald. For a proportion the intervals are Wilson’s
score interval and the exact Clopper-Pearson one (stats::binom.test());
the ratio’s is log-normal (Katz et al.), with no exact interval (NA),
and the difference’s is Newcombe’s hybrid score interval. With a zero
count the log-normal intervals are NA: no continuity correction is
made.
rep is a group’s share of the events over its share of the exposure
(or the trials): over 1 when the group is over-represented among the
events, as in a comparison of who is placed in segregation with who is
in custody.
References
Section titled “References”Katz, D., Baptista, J., Azen, S. P. and Pike, M. C. (1978). Obtaining confidence intervals for the risk ratio in cohort studies. Biometrics, 34(3), 469-474. doi:10.2307/2530610
Newcombe, R. G. (1998). Interval estimation for the difference between independent proportions: comparison of eleven methods. Statistics in Medicine, 17(8), 873-890. doi:10.1002/(SICI)1097-0258(19980430)17:8<873::AID-SIM779>3.0.CO;2-I
Examples
Section titled “Examples”# use-of-force incidents per 1,000 contacts by perceived racegrprr(c(white = 120, black = 95, other = 30), c(white = 60000, black = 21000, other = 15000), per = 1000)# proportions from one row per casegrprr(c(1, 0, 0, 1, 1, 0, 1, 1), grp = c(1, 1, 1, 1, 2, 2, 2, 2), type = "prop")Generated from the R help page: grprr in the R reference.