Learn R Programming

CLRtools (version 0.1.0)

check_coef_change: Assess Coefficient Change After Variable Removal

Description

Computes the percentage change in logistic regression coefficients (\(\Delta \hat{\beta}\%\)) as each additional variable is introduced to the model one at a time. Supports both standard logistic regression (via glm) and conditional logistic regression (via clogit) when a stratification variable is provided.

Usage

check_coef_change(data, yval, xpre, xcheck, strata = NULL)

Value

A data frame showing how the coefficients change when each variable in xcheck

is added to the model containing xpre.

Arguments

data

A data frame containing the outcome, predictors, and optional stratification variable.

yval

A string naming the binary outcome variable.

xpre

A character vector of variable names that are already selected for the model.

xcheck

A character vector of variable names to be added one-by-one for comparison.

strata

Optional; a string specifying the name of the stratification variable for conditional logistic regression.

Details

This function fits a logistic regression model using variables in xpre, and then adds each variable in xcheck one at a time to assess how the coefficients of the model change with the delta beta hat percentages. Useful for evaluating confounding or additional variable contribution. When strata is NULL, the function uses standard logistic regression (glm with binomial family). When strata is specified, conditional logistic regression is used instead via survival::clogit.

References

Hosmer, D. W., Lemeshow, S., & Sturdivant, R. X. (2013). Applied Logistic Regression (3rd ed.). John Wiley & Sons, Inc. The formulas for calculating residuals and diagnostics are adapted from this source.

See Also

delta.coefficient

Examples

Run this code
# Example from Hosmer et al., 2013
# Applied Logistic Regression (3rd ed.), Chapter 4

# Variables selected to evaluate
preliminar <- c('age', 'height', 'priorfrac', 'momfrac', 'armassist')

# Variable to evaluate for potential confounding
excluded <- c('raterisk')

# Assess coefficient change after adding 'raterisk'
check_coef_change(data = glow500, yval = 'fracture', xpre = preliminar, xcheck = excluded)

Run the code above in your browser using DataLab