Fit a Weighted Pooled Logistic Regression

Description

Fits a binomial (logit) generalized linear model from a formula and data, optionally weighted by a named column. This is the shared fitting primitive behind the package’s IP-weighted models (fit_outcome_hr() and predict_survival_ipw()): the weighted-GLM step now has a single, tested implementation. It is exported so sibling packages can reuse the same weighted pooled-logistic fit (see the discrete-time outcome-model consolidation discussion in the package’s issue tracker).

Usage

fit_weighted_logistic(data, formula, weight_col = NULL)

Arguments

data A data frame containing the model variables and, when weight_col is supplied, the weight column.
formula A model formula passed to stats::glm().
weight_col Name of a numeric weight column in data, or NULL (the default) for an unweighted fit.

Value

The fitted stats::glm object (binomial family, logit link).

See Also

fit_outcome_hr() and predict_survival_ipw(), which build their formula and call this function for the fit.

Examples

Code
library("ettbc")

df <- data.frame(
  y = c(0, 1, 0, 1, 1),
  x = c(1, 2, 3, 4, 5),
  w = c(1, 1, 2, 2, 1)
)
fit <- fit_weighted_logistic(df, y ~ x, weight_col = "w")
coef(fit)
(Intercept)           x 
  -3.410079    1.202284