Skip to contents

Fits the same Poisson log-link model as fast_poisson_regression_cpp (see that page for the full model and optimizer contract), with each observation's contribution to the log-likelihood, score, and IRLS working weights multiplied by a row weight weights[i]. Setting all weights to 1 recovers fast_poisson_regression_cpp exactly. Always fits with estimate_only = FALSE (there is no flag to skip the post-fit mu/ XtWX/score computation for this variant).

Usage

fast_poisson_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 X if desired.

y

A numeric vector of the response variable, expected to be nonnegative-integer counts.

weights

A numeric vector of nonnegative weights, one per observation.

warm_start_beta

Optional starting values for coefficients \(\beta\). If provided, smart_cold_start is ignored.

smart_cold_start

Logical. If TRUE and no warm_start_beta is 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_idx at.

optimization_alg

Optimization algorithm: "irls" (default), "lbfgs", or "newton_raphson".

warm_start_weights

Accepted but unused; see fast_poisson_regression_cpp Details.

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\).

mu

The fitted means \(\hat\mu_i\).

XtWX, fisher_information

Two aliases for the same (weighted) curvature matrix \(X^\top W X\), \(W = \mathrm{diag}(\code{weights}_i \hat\mu_i)\), at the fitted coefficients.

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 algorithm converged.

iterations

The number of iterations performed.

gradient_norm

The norm of the score vector at convergence.

See also

fast_poisson_regression_cpp for the unweighted variant and full model documentation.