purposeful_step_3: Purposeful selection step #3

View source: R/purposeful-step-3.R

purposeful_step_3R Documentation

Purposeful selection step #3

Description

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.

Usage

purposeful_step_3(
  data,
  outcome,
  ref_level = NULL,
  predictors,
  potential_confounders = NULL,
  ...
)

Arguments

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 NULL and the model fit will determine the reference level.

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.

Value

A tibble

References

Hosmer DW, Lemeshow S (2000) Applied Logistic Regression. John Wiley & Sons, Inc.

Examples

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"))



emilelatour/purposeful documentation built on Jan. 6, 2023, 8:04 a.m.