
Fast Logistic Regression with Targeted Variance (C++ Backend)
Source:R/helper_glm_fit.R
fast_logistic_regression_with_var_cpp.RdFits the same logistic regression model as
fast_logistic_regression_cpp (see that page for the full
model and log-odds-ratio interpretation) and additionally computes the
variance of two coefficients — the caller-selected j-th coefficient
and, separately, the 2nd coefficient (the package's usual treatment-effect
position) — via a targeted diagonal-entry inversion of the working-weights
Fisher information, rather than a full matrix inverse. Unlike
fast_logistic_regression_cpp, maxit and tol are
not exposed here: they are fixed internally at 100 iterations and
1e-8 tolerance.
Usage
fast_logistic_regression_with_var_cpp(
X,
y,
j = 2L,
warm_start_beta = NULL,
smart_cold_start = FALSE,
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).
- j
1-based index (into
X's columns) of the coefficient to computessq_b_jfor. Defaults to 2.- 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.- 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 with components b/params (estimated
coefficients \(\hat\beta\), identical to each other),
ssq_b_j/ssq_b_2 (the two targeted coefficient variances
described in Details), score (the score vector at
\(\hat\beta\)), observed_information/fisher_information/
information (three aliases for the same working-weights curvature
matrix, tagged information_type = "fisher"), hessian (the
negative of that matrix), neg_loglik/neg_ll (aliases for the
negative log-likelihood), loglik (its negation), converged
(logical, gradient_norm < tol, uniform across optimizers),
num_iter, hit_iteration_cap (logical, mutually exclusive
with converged), and gradient_norm.
Details
Variance computation. The working-weights Fisher information
\(X^\top W X\) is restricted to the free (non-fixed_idx)
parameters; ssq_b_j and ssq_b_2 are each obtained via a
single targeted diagonal-entry inversion
(compute_diagonal_inverse_entry()) at the free-parameter position
corresponding to j and to column 2, respectively — NA if the
relevant coefficient is out of range or was itself fixed via
fixed_idx. ssq_b_2 is always computed (when ncol(X) >= 2)
regardless of what j is, so a caller interested in the treatment
effect's variance does not need to pass j = 2 explicitly.
See also
fast_logistic_regression_cpp for the estimate-only
variant and the full model documentation.