Compares bivariate responses between two groups in terms of odds ratios along with a confidence interval.
Usage
or_glm(data, conf_level)
or_clogit(data, conf_level)
s_odds_ratio(
df,
.var,
.ref_group,
.in_ref_col,
.df_row,
variables = list(arm = NULL, strata = NULL),
conf_level = 0.95,
groups_list = NULL
)
a_odds_ratio(
df,
.var,
.ref_group,
.in_ref_col,
.df_row,
variables = list(arm = NULL, strata = NULL),
conf_level = 0.95,
groups_list = NULL
)
estimate_odds_ratio(
lyt,
vars,
...,
show_labels = "hidden",
table_names = vars,
.stats = "or_ci",
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
Arguments
- data
(
data frame
)
with at least the variablesrsp
,grp
, and in additionstrata
foror_clogit()
.- conf_level
(
proportion
)
confidence level of the interval.- df
(
data frame
)
data set containing all analysis variables.- .var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- .ref_group
(
data frame
orvector
)
the data corresponding to the reference group.- .in_ref_col
(
logical
)TRUE
when working with the reference level,FALSE
otherwise.- .df_row
(
data frame
)
data frame across all of the columns for the given row split.- variables
(named
list
ofstring
)
list of additional analysis variables.- groups_list
(named
list
ofcharacter
)
specifies the new group levels via the names and the levels that belong to it in the character vectors that are elements of the list.- lyt
(
layout
)
input layout where analyses will be added to.- vars
(
character
)
variable names for the primary analysis variable to be iterated over.- ...
arguments passed to
s_odds_ratio()
.- show_labels
label visibility: one of "default", "visible" and "hidden".
- table_names
(
character
)
this can be customized in case that the samevars
are analyzed multiple times, to avoid warnings fromrtables
.- .stats
(
character
)
statistics to select for the table.- .formats
(named
character
orlist
)
formats for the statistics.- .labels
(named
character
)
labels for the statistics (without indent).- .indent_mods
(named
integer
)
indent modifiers for the labels.
Details
This function uses either logistic regression for unstratified
analyses, or conditional logistic regression for stratified analyses.
The Wald confidence interval with the specified confidence level is
calculated. Note that, for stratified analyses, there is currently no
implementation for conditional likelihood confidence intervals,
therefore the likelihood confidence interval as an option is not yet
available. Besides, when rsp
contains only responders or non-responders,
then the result values will be NA
, because no odds ratio estimation is
possible.
Functions
or_glm()
: estimates the odds ratio based onstats::glm()
. Note that there must be exactly 2 groups indata
as specified by thegrp
variable.or_clogit()
: estimates the odds ratio based onsurvival::clogit()
. This is done for the whole data set including all groups, since the results are not the same as when doing pairwise comparisons between the groups.s_odds_ratio()
: Statistics function which estimates the odds ratio between a treatment and a control. Note that avariables
list witharm
andstrata
names needs to be passed if a stratified analysis is required.a_odds_ratio()
: Formatted Analysis function which can be further customized by callingrtables::make_afun()
on it. It is used asafun
inrtables::analyze()
.estimate_odds_ratio()
: Layout creating function which can be used for creating tables, which can take statistics function arguments and additional format arguments (see below).
Examples
# Data with 2 groups.
data <- data.frame(
rsp = as.logical(c(1, 1, 0, 1, 0, 0, 1, 1)),
grp = letters[c(1, 1, 1, 2, 2, 2, 1, 2)],
strata = letters[c(1, 2, 1, 2, 2, 2, 1, 2)],
stringsAsFactors = TRUE
)
# Odds ratio based on glm.
or_glm(data, conf_level = 0.95)
#> $or_ci
#> est lcl ucl
#> 0.33333333 0.01669735 6.65441589
#>
#> $n_tot
#> n_tot
#> 8
#>
# Data with 3 groups.
data <- data.frame(
rsp = as.logical(c(1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0)),
grp = letters[c(1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3)],
strata = LETTERS[c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)],
stringsAsFactors = TRUE
)
# Odds ratio based on stratified estimation by conditional logistic regression.
or_clogit(data, conf_level = 0.95)
#> $or_ci
#> $or_ci$b
#> est lcl ucl
#> 0.28814553 0.02981009 2.78522598
#>
#> $or_ci$c
#> est lcl ucl
#> 0.5367919 0.0673365 4.2791881
#>
#>
#> $n_tot
#> n_tot
#> 20
#>
set.seed(12)
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50), levels = c("B", "A")),
strata = factor(sample(c("C", "D"), 100, TRUE))
)
# Unstratified analysis.
s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta
)
#> $or_ci
#> est lcl ucl
#> 0.8484848 0.3831831 1.8788053
#> attr(,"label")
#> [1] "Odds Ratio (95% CI)"
#>
#> $n_tot
#> n_tot
#> 100
#> attr(,"label")
#> [1] "Total n"
#>
# Stratified analysis.
s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata")
)
#> $or_ci
#> est lcl ucl
#> 0.7689750 0.3424155 1.7269154
#> attr(,"label")
#> [1] "Odds Ratio (95% CI)"
#>
#> $n_tot
#> n_tot
#> 100
#> attr(,"label")
#> [1] "Total n"
#>
a_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta
)
#> RowsVerticalSection (in_rows) object print method:
#> ----------------------------
#> row_name formatted_cell indent_mod row_label
#> 1 or_ci 0.85 (0.38 - 1.88) 1 Odds Ratio (95% CI)
#> 2 n_tot 100 0 Total n
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50))
)
l <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "B") %>%
estimate_odds_ratio(vars = "rsp")
build_table(l, df = dta)
#> B A
#> ————————————————————————————————————————————
#> Odds Ratio (95% CI) 0.72 (0.33 - 1.60)