View source: R/purposeful-step-3.R
purposeful_step_3 | R Documentation |
Assess whether variables removed in steps #1 and #2 are potential confounders. Add them back to the model if they are. Recommendation is that if the changes in beta coefficients (log odds) exceed 20%, then the excluded variable could be a confounder and should be included in the reduced model due to its effect on the other estimates.
purposeful_step_3( data, outcome, ref_level = NULL, predictors, potential_confounders = NULL, ... )
data |
A tibble or data frame with the full data set. |
outcome |
Character string. The dependent variable (outcome) for logistic regression. |
ref_level |
Character string. The factor level of outcome variable that
corresponds to the true condition (1). If not provided then default is
|
predictors |
Character vector. Independent variables (predictors/covariates) for univariable and/or multivariable modelling. |
potential_confounders |
Character vector. Those variables removed in steps #1 and #2. |
... |
Additional arguments. |
A tibble
Hosmer DW, Lemeshow S (2000) Applied Logistic Regression. John Wiley & Sons, Inc.
library(dplyr) #### Sample data set -------------------------------- set.seed(888) age <- abs(round(rnorm(n = 1000, mean = 67, sd = 14))) lac <- abs(round(rnorm(n = 1000, mean = 5, sd = 3), 1)) gender <-factor(rbinom(n = 1000, size = 1, prob = 0.6), labels = c("male", "female")) wbc <- abs(round(rnorm(n = 1000, mean = 10, sd = 3), 1)) hb <- abs(round(rnorm(n = 1000, mean = 120, sd = 40))) z <- 0.1 * age - 0.02 * hb + lac - 10 pr = 1 / (1 + exp(-z)) y = rbinom(1000, 1, pr) mort <- factor(rbinom(1000, 1, pr), labels = c("alive", "dead")) data <- tibble::tibble(age, gender, lac, wbc, hb, mort) #### Example 1 -------------------------------- purposeful_step_3(data = data, outcome = "mort", predictors = c("age", "lac"), ref_level = "dead", potential_confounders = c("gender", "wbc")) #### Example 2 -------------------------------- purposeful_step_3(data = data, outcome = "mort", predictors = c("age", "lac"), potential_confounders = c("gender", "wbc"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.