h_logistic_regression {tern} | R Documentation |
Helper functions for multivariate logistic regression
Description
Helper functions used in calculations for logistic regression.
Usage
h_get_interaction_vars(fit_glm)
h_interaction_coef_name(
interaction_vars,
first_var_with_level,
second_var_with_level
)
h_or_cat_interaction(
odds_ratio_var,
interaction_var,
fit_glm,
conf_level = 0.95
)
h_or_cont_interaction(
odds_ratio_var,
interaction_var,
fit_glm,
at = NULL,
conf_level = 0.95
)
h_or_interaction(
odds_ratio_var,
interaction_var,
fit_glm,
at = NULL,
conf_level = 0.95
)
h_simple_term_labels(terms, table)
h_interaction_term_labels(terms1, terms2, table, any = FALSE)
h_glm_simple_term_extract(x, fit_glm)
h_glm_interaction_extract(x, fit_glm)
h_glm_inter_term_extract(odds_ratio_var, interaction_var, fit_glm, ...)
h_logistic_simple_terms(x, fit_glm, conf_level = 0.95)
h_logistic_inter_terms(x, fit_glm, conf_level = 0.95, at = NULL)
Arguments
fit_glm |
( |
interaction_vars |
( |
first_var_with_level |
( |
second_var_with_level |
( |
odds_ratio_var |
( |
interaction_var |
( |
conf_level |
( |
at |
( |
terms |
( |
table |
( |
terms1 |
( |
terms2 |
( |
any |
( |
x |
( |
... |
additional arguments for the lower level functions. |
Value
Vector of names of interaction variables.
Name of coefficient.
Odds ratio.
Odds ratio.
Odds ratio.
Term labels containing numbers of patients.
Term labels containing numbers of patients.
Tabulated main effect results from a logistic regression model.
Tabulated interaction term results from a logistic regression model.
A data.frame
of tabulated interaction term results from a logistic regression model.
Tabulated statistics for the given variable(s) from the logistic regression model.
Tabulated statistics for the given variable(s) from the logistic regression model.
Functions
-
h_get_interaction_vars()
: Helper function to extract interaction variable names from a fitted model assuming only one interaction term. -
h_interaction_coef_name()
: Helper function to get the right coefficient name from the interaction variable names and the given levels. The main value here is that the order of first and second variable is checked in theinteraction_vars
input. -
h_or_cat_interaction()
: Helper function to calculate the odds ratio estimates for the case when both the odds ratio and the interaction variable are categorical. -
h_or_cont_interaction()
: Helper function to calculate the odds ratio estimates for the case when either the odds ratio or the interaction variable is continuous. -
h_or_interaction()
: Helper function to calculate the odds ratio estimates in case of an interaction. This is a wrapper forh_or_cont_interaction()
andh_or_cat_interaction()
. -
h_simple_term_labels()
: Helper function to construct term labels from simple terms and the table of numbers of patients. -
h_interaction_term_labels()
: Helper function to construct term labels from interaction terms and the table of numbers of patients. -
h_glm_simple_term_extract()
: Helper function to tabulate the main effect results of a (conditional) logistic regression model. -
h_glm_interaction_extract()
: Helper function to tabulate the interaction term results of a logistic regression model. -
h_glm_inter_term_extract()
: Helper function to tabulate the interaction results of a logistic regression model. This basically is a wrapper forh_or_interaction()
andh_glm_simple_term_extract()
which puts the results in the right data frame format. -
h_logistic_simple_terms()
: Helper function to tabulate the results including odds ratios and confidence intervals of simple terms. -
h_logistic_inter_terms()
: Helper function to tabulate the results including odds ratios and confidence intervals of interaction terms.
Note
We don't provide a function for the case when both variables are continuous because this does not arise in this table, as the treatment arm variable will always be involved and categorical.
Examples
library(dplyr)
library(broom)
adrs_f <- tern_ex_adrs %>%
filter(PARAMCD == "BESRSPI") %>%
filter(RACE %in% c("ASIAN", "WHITE", "BLACK OR AFRICAN AMERICAN")) %>%
mutate(
Response = case_when(AVALC %in% c("PR", "CR") ~ 1, TRUE ~ 0),
RACE = factor(RACE),
SEX = factor(SEX)
)
formatters::var_labels(adrs_f) <- c(formatters::var_labels(tern_ex_adrs), Response = "Response")
mod1 <- fit_logistic(
data = adrs_f,
variables = list(
response = "Response",
arm = "ARMCD",
covariates = c("AGE", "RACE")
)
)
mod2 <- fit_logistic(
data = adrs_f,
variables = list(
response = "Response",
arm = "ARMCD",
covariates = c("AGE", "RACE"),
interaction = "AGE"
)
)
h_glm_simple_term_extract("AGE", mod1)
h_glm_simple_term_extract("ARMCD", mod1)
h_glm_interaction_extract("ARMCD:AGE", mod2)
h_glm_inter_term_extract("AGE", "ARMCD", mod2)
h_logistic_simple_terms("AGE", mod1)
h_logistic_inter_terms(c("RACE", "AGE", "ARMCD", "AGE:ARMCD"), mod2)