
Fast Quasi-Poisson Regression with Variance Calculation (C++ Backend)
Source:R/helper_glm_fit.R
fast_quasipoisson_regression_with_var_cpp.RdFits the same Poisson log-link mean model as fast_poisson_regression_cpp
(see that page for the full model and optimizer contract; point estimates \(\hat\beta\)
are identical to what that function would return), but instead of the plain Poisson
Fisher-information-based variance, scales it by an estimated overdispersion
parameter to obtain quasi-likelihood standard errors that are robust to
variance-mean deviations from the strict Poisson assumption
\(\mathrm{Var}(Y_i) = \mu_i\). The dispersion is the Pearson-statistic-based
moment estimator,
$$\hat\phi = \frac{1}{n-p}\sum_{i=1}^n \frac{(y_i - \hat\mu_i)^2}{\hat\mu_i},$$
computed only when the residual degrees of freedom \(n - p > 0\); the reported
coefficient variances are then \(\widehat{\mathrm{Var}}(\hat\beta_k) = \hat\phi
\, [(X^\top \hat W X)^{-1}]_{kk}\) (the ordinary Poisson Fisher information scaled by
\(\hat\phi\)), matching the standard quasi-Poisson GLM correction (as in
stats::glm(family = quasipoisson())). If \(n \le p\), or \(\hat\phi\)
comes out non-finite or non-positive, ssq_b_j/ssq_b_2/dispersion
are left at their NA defaults (point estimates b and mu are
still returned).
Usage
fast_quasipoisson_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
A numeric vector of the estimated Poisson regression coefficients \(\hat\beta\) (point estimates, unaffected by the dispersion correction).
- ssq_b_j
The dispersion-scaled variance of the \(j\)-th coefficient estimator;
NAifjindexes a fixed coefficient or the dispersion estimate is unusable.- ssq_b_2
The dispersion-scaled variance of the second coefficient estimator specifically (typically the treatment effect), regardless of what
jis; equal tossq_b_jwhenj = 2.- dispersion
The estimated Pearson-based overdispersion parameter \(\hat\phi\), or
NAif the residual degrees of freedom are not positive.- mu
The fitted means \(\hat\mu_i\).
- converged
A logical value indicating whether the algorithm converged.
- iterations
The number of iterations performed.
- gradient_norm
The norm of the score vector at convergence.
See also
fast_poisson_regression_with_var_cpp for the plain
(non-overdispersion-corrected) variance variant; fast_poisson_regression_cpp
for the estimate-only variant and full mean-model documentation.