rift_risk_ratio() and rift_risk_difference() estimate the ratio and the
difference of the risk of a binary outcome between the levels of an
exposure, each level against the first, optionally adjusted for
covariates, with a confidence interval. They are the estimators behind the
"rr" and "rd" rows of tbl_rift(), exported so they can be called on
their own, passed to add_difference() as a custom method, or wrapped in a
stat_fns function of tbl_custom_summary().
Four approaches are available, all computed in base R:
"margstd_delta"(the default): marginal standardization after logistic regression. The modeloutcome ~ by + adj.varsis fit withglm(family = binomial()), every observation's risk is predicted with the exposure set to each level in turn, the predictions are averaged per level, and the ratio or difference of the averages is reported with a delta-method standard error (Localio, Margolis and Berlin, 2007). Without covariates this is the crude risk ratio with its log-scale interval and the crude risk difference with its Wald interval."glm": a binomial model with a log link (ratio) or an identity link (difference) (Wacholder, 1986). These models often fail to converge."glm_startp": the same binomial model started at the coefficients of the Poisson model with the same link (Spiegelman and Hertzmark, 2005)."robpoisson": a Poisson model with a log link (ratio) or an identity link (difference) with the HC0 sandwich variance (Zou, 2004).
The limits are large-sample (Wald) limits at conf.level, on the log scale
for ratios. The names of the approaches are those of the risks package,
which computes the same estimates.
Usage
rift_risk_ratio(
data,
variable,
by,
adj.vars = NULL,
value = NULL,
approach = c("margstd_delta", "glm", "glm_startp", "robpoisson"),
conf.level = 0.95,
test.args = list(),
...
)
rift_risk_difference(
data,
variable,
by,
adj.vars = NULL,
value = NULL,
approach = c("margstd_delta", "glm", "glm_startp", "robpoisson"),
conf.level = 0.95,
test.args = list(),
...
)Arguments
- data
(
data.frame)
A data frame.- variable
(
string)
The outcome column:0/1, logical, or a column whose event value is given invalue.- by
(
string)
The exposure column, a factor, character or logical. Its first level is the reference.- adj.vars
(
character)
Covariates added to the model. Default isNULL.- value
The value of
variablethat counts as the event. Default isNULL, which uses1for a0/1variable,TRUEfor a logical, and theyesof a yes/no variable.- approach
(
string)
One of"margstd_delta","glm","glm_startp"and"robpoisson", described above.- conf.level
(
scalar numeric)
Confidence level. Default is0.95.- test.args
(named
list)
Anapproachgiven here wins over the argument, soadd_difference(test.args = ~ list(approach = "robpoisson"))reaches the function. Default is an empty list.- ...
Not used. Accepted so that the functions can be passed to
add_difference(), which calls them with more arguments.
Value
A data frame with one row per level of by other than the first:
level, reference (the first level), estimate, std.error (on the
log scale for a ratio), statistic, p.value, conf.low, conf.high
and method. With a two-level by the frame has one row, the shape
add_difference() expects from a custom method.
In add_difference()
add_difference(test = ~ "rift_risk_ratio") compares the second level of
by with the first, the direction of a regression coefficient and the
opposite of "prop.test", which subtracts the second from the first.
add_difference() formats a dichotomous variable's estimate as a
percentage by default, so pass estimate_fun = ~ label_style_ratio() for
a ratio, and rename the header with modify_header().
References
Localio AR, Margolis DJ, Berlin JA. Relative risks and confidence intervals were easily computed indirectly from multivariable logistic regression. J Clin Epidemiol 2007;60:874-82.
Wacholder S. Binomial regression in GLIM: estimating risk ratios and risk differences. Am J Epidemiol 1986;123:174-84.
Spiegelman D, Hertzmark E. Easy SAS calculations for risk or prevalence ratios and differences. Am J Epidemiol 2005;162:199-200.
Zou G. A modified Poisson regression approach to prospective studies with binary data. Am J Epidemiol 2004;159:702-6.
Stopsack KH. risks: Estimate risk ratios and risk differences using regression. R package, https://stopsack.github.io/risks/.
See also
Other results tables:
rift_rate(),
rift_survival,
tbl_rift(),
tbl_rift_design
Examples
# Example 1 ----------------------------------
# the crude risk ratio and risk difference of response by treatment
rift_risk_ratio(trial, variable = "response", by = "trt")
#> level reference estimate std.error statistic p.value conf.low conf.high
#> 1 Drug B Drug A 1.014545 0.2576207 0.05605406 0.9552987 0.6123284 1.680965
#> method
#> 1 Risk ratio (marginal standardization, delta method)
rift_risk_difference(trial, variable = "response", by = "trt")
#> level reference estimate std.error statistic p.value conf.low
#> 1 Drug B Drug A 0.00344086 0.06136707 0.05607014 0.9552859 -0.1168364
#> conf.high method
#> 1 0.1237181 Risk difference (marginal standardization, delta method)
# Example 2 ----------------------------------
# adjusted for grade, with a Poisson model and robust variance
rift_risk_ratio(trial, "response", "trt", adj.vars = "grade", approach = "robpoisson")
#> level reference estimate std.error statistic p.value conf.low conf.high
#> 1 Drug B Drug A 1.078426 0.2542111 0.2970079 0.7664605 0.6552478 1.774906
#> method
#> 1 Risk ratio (Poisson model, robust variance)
# Example 3 ----------------------------------
# as a custom method of add_difference()
trial |>
tbl_summary(by = trt, include = response, missing = "no") |>
add_difference(test = ~ "rift_risk_ratio", estimate_fun = ~ label_style_ratio()) |>
modify_header(estimate = "**Risk Ratio**")