Functions to calculate odds ratios in estimate_odds_ratio().
Arguments
- data
(
data.frame)
data frame containing at least the variablesrspandgrp, and optionallystrataforor_clogit().- conf_level
(
proportion)
confidence level of the interval.
Functions
or_glm(): Estimates the odds ratio based onstats::glm(). Note that there must be exactly 2 groups indataas specified by thegrpvariable.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.
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
#>