
Fast Weighted Logistic Regression, Estimate Only (C++ Backend)
Source:R/helper_glm_fit.R
fast_logistic_regression_weighted_cpp.RdFits the same logistic regression model as
fast_logistic_regression_cpp (see that page for the full
model, log-odds-ratio interpretation, and optimizer contract), with each
observation's contribution to the log-likelihood and IRLS working weights
multiplied by a row weight weights[i]. Setting all weights to 1
recovers fast_logistic_regression_cpp exactly; this is the
backend used when the logistic model must be fit on bootstrap-reweighted or
otherwise weighted data.
Usage
fast_logistic_regression_weighted_cpp(
X,
y,
weights,
warm_start_beta = NULL,
smart_cold_start = FALSE,
maxit = 100L,
tol = 1e-8,
fixed_idx = NULL,
fixed_values = NULL,
optimization_alg = "irls",
warm_start_weights = NULL,
warm_start_fisher_info = NULL
)Arguments
- X
A numeric matrix of predictor variables. It is assumed that an intercept column (e.g., a column of ones) is already included in
Xif desired.- y
A numeric vector of the response variable, expected to be binary (0 or 1).
- weights
A numeric vector of weights for each observation.
- warm_start_beta
Optional starting values for coefficients \(\beta\). If provided,
smart_cold_startis ignored.- smart_cold_start
Logical. If
TRUEand nowarm_start_betais supplied, use an OLS-based initial guess rather than a zero cold start.- maxit
Maximum number of iterations for the IRLS algorithm. Defaults to 100.
- tol
Convergence tolerance. Defaults to 1e-8.
- fixed_idx
Optional integer indices of coefficients to hold fixed rather than estimate.
- fixed_values
Optional values to fix the parameters named by
fixed_idxat.- optimization_alg
Optimization algorithm:
"irls"(default),"lbfgs", or"newton_raphson"; see.normalize_optimizer_algorithm.- warm_start_weights
Optional initial IRLS working weights for the first iteration.
- warm_start_fisher_info
Optional initial Fisher Information matrix to warm-start curvature information.
Value
A list containing the following components:
- b
A numeric vector of the estimated logistic regression coefficients \(\hat\beta\).
- mu
The fitted probabilities \(\hat\mu_i\).
- XtWX, fisher_information
Two aliases for the same working-weights curvature matrix \(X^\top W X\) at the final iteration.
- score
The (weighted) score vector at the fitted coefficients.
- neg_ll
The weighted negative log-likelihood at the fitted coefficients.
- converged
A logical value indicating whether the final gradient norm was below
tol(gradient_norm < tol); uniform across the"irls"/"lbfgs"optimizers.- num_iter
The number of optimizer iterations performed.
- hit_iteration_cap
A logical value, mutually exclusive with
converged:TRUEiff the optimizer exhaustedmaxititerations without meeting the gradient-norm convergence criterion.- gradient_norm
The norm of the score vector at the returned coefficients.
See also
fast_logistic_regression_cpp for the unweighted model
and full documentation.