a_relative_risk {junco} | R Documentation |
Relative risk estimation
Description
The analysis function a_relative_risk()
is used to create a layout element
to estimate the relative risk for response within a studied population. Only
the CMH method is available currently.
The primary analysis variable, vars
, is a logical variable indicating
whether a response has occurred for each record.
A stratification variable must be supplied via the
strata
element of the variables
argument.
Usage
a_relative_risk(
df,
.var,
ref_path,
.spl_context,
...,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
s_relative_risk(
df,
.var,
.ref_group,
.in_ref_col,
variables = list(strata = NULL),
conf_level = 0.95,
method = "cmh",
weights_method = "cmh"
)
Arguments
df |
( |
.var |
( |
ref_path |
( |
.spl_context |
( |
... |
Additional arguments passed to the statistics function. |
.stats |
( |
.formats |
( |
.labels |
( |
.indent_mods |
( |
.ref_group |
( |
.in_ref_col |
( |
variables |
( |
conf_level |
( |
method |
( |
weights_method |
( |
Details
The variance of the CMH relative risk estimate is calculated using the Greenland and Robins (1985) variance estimation.
Value
-
a_relative_risk()
returns the corresponding list with formattedrtables::CellValue()
.
-
s_relative_risk()
returns a named list of elementsrel_risk_ci
andpval
.
Functions
-
a_relative_risk()
: Formatted analysis function which is used asafun
. Note that the junco specificref_path
and.spl_context
arguments are used for reference column information. -
s_relative_risk()
: Statistics function estimating the relative risk for response.
Note
This has been adapted from the odds_ratio
functions in the tern
package.
Examples
nex <- 100
dta <- data.frame(
"rsp" = sample(c(TRUE, FALSE), nex, TRUE),
"grp" = sample(c("A", "B"), nex, TRUE),
"f1" = sample(c("a1", "a2"), nex, TRUE),
"f2" = sample(c("x", "y", "z"), nex, TRUE),
stringsAsFactors = TRUE
)
l <- basic_table() |>
split_cols_by(var = "grp") |>
analyze(
vars = "rsp",
afun = a_relative_risk,
extra_args = list(
conf_level = 0.90,
variables = list(strata = "f1"),
ref_path = c("grp", "B")
)
)
build_table(l, df = dta)
nex <- 100
dta <- data.frame(
"rsp" = sample(c(TRUE, FALSE), nex, TRUE),
"grp" = sample(c("A", "B"), nex, TRUE),
"f1" = sample(c("a1", "a2"), nex, TRUE),
"f2" = sample(c("x", "y", "z"), nex, TRUE),
stringsAsFactors = TRUE
)
s_relative_risk(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
variables = list(strata = c("f1", "f2")),
conf_level = 0.90
)