purposeful_step_1: Purposeful selection step #1

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

purposeful_step_1R Documentation

Purposeful selection step #1

Description

Univariable logistic regression for variables of interest. A simple logistic regression is fir for each variable. Significance is judged at a higher level for inclusion (suggested 0.25).

Usage

purposeful_step_1(
  data,
  outcome,
  predictors,
  ref_level = NULL,
  cutoff_value = 0.25,
  conf_level = 0.95,
  format = FALSE,
  exponentiate = TRUE,
  digits = 1,
  ...
)

Arguments

data

A tibble or data frame with the full data set.

outcome

Character string. The dependent variable (outcome) for logistic regression.

predictors

Character vector. Independent variables (predictors/covariates) for univariable and/or multivariable modelling.

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.

cutoff_value

Numeric between 0 and 1. Include any covariate with p-value less than this value. Suggested default is 0.25.

conf_level

The confidence level to use for the confidence interval. Must be strictly greater than 0 and less than 1. Defaults to 0.95, which corresponds to a 95 percent confidence interval.

format

Display format in case I need to escape some characters. A place holder for now in case I need it in the future. Default is "html".

exponentiate

Logical indicating whether or not to exponentiate the the coefficient estimates. This is typical for logistic and multinomial regressions, but a bad idea if there is no log or logit link. Defaults to TRUE.

digits

Integer; number of decimals to round to.

...

Additional arguments.

Value

Atibble

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_1(data = data,
                  outcome = "mort",
                  predictors = c("age", "gender", "wbc", "lac"),
                  # ref_level = "dead",
                  format = TRUE,
                  exponentiate = FALSE)

#### Example 2 --------------------------------

purposeful_step_1(data = data,
                  outcome = "mort",
                  predictors = c("age", "gender", "wbc", "lac"),
                  ref_level = "dead",
                  format = FALSE,
                  exponentiate = TRUE)

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