
Fast Poisson Regression with Variance Calculation (C++ Backend)
Source:R/helper_glm_fit.R
fast_poisson_regression_with_var_cpp.RdFits the same Poisson log-link model as fast_poisson_regression_cpp
(see that page for the full model and optimizer contract; always with
estimate_only = FALSE), and additionally inverts the fitted Fisher
information matrix (Eigen::LDLT on the free-coefficient submatrix, via
compute_diagonal_inverse_entry) to report the variance of two
coefficients.
Usage
fast_poisson_regression_with_var_cpp(
X,
y,
j = 2L,
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 nonnegative-integer counts.
- j
The 1-indexed coefficient whose variance to compute in
ssq_b_j. 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 a Poisson-specific heuristic initial guess rather than a zero cold start.- maxit
Maximum number of iterations. 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".- warm_start_weights
Accepted but unused; see
fast_poisson_regression_cppDetails.- warm_start_fisher_info
Optional initial curvature (information) matrix to warm-start the first iteration.
Value
A list containing the following components:
- b, params
A numeric vector of the estimated Poisson regression coefficients \(\hat\beta\) (both aliases of the same vector).
- ssq_b_j
The variance of the \(j\)-th coefficient estimator;
NAifjindexes a fixed coefficient.- ssq_b_2
The variance of the second coefficient estimator specifically (typically the treatment effect), regardless of what
jis; equal tossq_b_jwhenj = 2.NAif the second column is a fixed coefficient.- mu
The fitted means \(\hat\mu_i\).
- converged
A logical value indicating whether the final gradient norm was below
tol(gradient_norm < tol); uniform across the"irls"/"lbfgs"/"newton_raphson"optimizers.- num_iter
The number of iterations performed.
- score
The score vector at the fitted coefficients.
- observed_information, fisher_information, information
Three aliases for the same \(X^\top W X\) curvature matrix (
information_typeis always"fisher").- hessian
The negative of that same matrix (the actual Hessian of the log-likelihood).
- neg_loglik, neg_ll
The negative log-likelihood at the fitted coefficients (two aliases).
- loglik
The log-likelihood (
-neg_ll), orNAifneg_llis non-finite.- 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_poisson_regression_cpp for the estimate-only variant and full
model documentation; fast_quasipoisson_regression_with_var_cpp for the
overdispersion-corrected variant.