Learn R Programming

CLRtools (version 0.1.0)

univariable.clogmodels: Univariable Conditional Logistic Regression Models

Description

This function fits separate univariable conditional logistic regression models for a specified outcome and a list of explanatory variables, using the clogit function from the survival package. It returns a summary table with coefficients, standard errors, p-values, and optionally odds ratios with confidence intervals. The strata vector must be in the same order as the observations in the data frame.

Usage

univariable.clogmodels(
  data,
  yval,
  xval,
  strata,
  OR = FALSE,
  inc.or = NULL,
  confidence.level = 0.95
)

Value

A data frame with coefficients from the univariable models, standard errors, p-values, and, if requested, odds ratios with lower and upper confidence limits.

Arguments

data

A data frame containing the outcome, predictors, and strata variables

yval

A string indicating the name of the binary outcome variable.

xval

A character vector of predictor variable names for which univariable models will be fit.

strata

A character string specifying the name of the stratification variable (e.g., matching ID).

OR

Logical; if TRUE, odds ratios and their confidence intervals are returned. Default to FALSE.

inc.or

A numeric vector specifying the unit increment to apply when calculating odds ratios for each coefficient. Required if OR = TRUE. The length of inc.or must match the number of coefficients produced across all univariable models (including dummy variables for factor levels, if applicable). It must align with the order of xval: for each variable, include one value per resulting coefficient.

confidence.level

The confidence level to use for interval estimation of odds ratios. Defaults to 0.95.

Details

Each predictor in xval is fit in a separate model with the outcome and stratification variable. When OR = TRUE, the user must supply inc.or, a vector of increments matching the number of coefficients across all univariable models (i.e., including levels of factors if applicable). The function assumes that the outcome is binary and numeric (0/1); it will attempt to coerce it if not.

Examples

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

 # Convert 'fracture' to binary (0 = No, 1 = Yes)
glow11m$fracture <- ifelse(glow11m$fracture == "Yes", 1, 0)

# Define variables to evaluate
unvariables <- c(
  "height", "weight", "bmi", "priorfrac", "premeno", "momfrac",
  "armassist", "smoke", "raterisk")

# Define value ranges used to interpret odds ratios (Optional)
val.pe <- c(10, 10, 3, 1, 1, 1, 1, 1, 1, 1)

# Run univariable conditional logistic regressions
univariable.clogmodels(glow11m, yval = 'fracture', xval = unvariables,
                        strata = 'pair', OR = TRUE, inc.or = val.pe)

Run the code above in your browser using DataLab