Learn R Programming

CLRtools (version 0.1.0)

cov.patterns: Extract Unique Covariate Patterns from a Logistic Regression Model

Description

Returns a summary of unique covariate patterns from a fitted logistic regression model, including the number of observations per pattern and the estimated probability.

Usage

cov.patterns(model)

Value

A data frame where each row corresponds to a unique covariate pattern. The output includes:

y_j

The number of observed events (cases) for each pattern.

m

The number of observations sharing that pattern.

est.prob

The estimated probability from the fitted model for that pattern.

Covariate columns

The covariates used in the model, showing the pattern structure.

Arguments

model

A fitted logistic regression model object, typically from glm() with family = binomial.

Details

This function summarizes the unique covariate patterns in the data, capturing the combinations of predictor values across observations. It calculates the frequency of each pattern, the number of events (cases), and the estimated probability for each combination of covariates.

Examples

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

# Recode 'raterisk' into a binary variable 'raterisk_cat'
glow500 <- dplyr::mutate(
  glow500,
  raterisk_cat = dplyr::case_when(
    raterisk %in% c("Less", "Same") ~ "C1",
    raterisk == "Greater" ~ "C2"
  )
)

# Fit a multiple logistic regression model with interactions
model.int <- glm(
  fracture ~ age + height + priorfrac + momfrac + armassist +
    raterisk_cat + age * priorfrac + momfrac * armassist,
  family = binomial,
  data = glow500
)

# Examine covariate patterns from the fitted model
X.cv <- cov.patterns(model.int)
head(X.cv, n=10)

Run the code above in your browser using DataLab