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; 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 X if 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_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, 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; NA if j indexes a fixed coefficient.

ssq_b_2

The variance of the second coefficient estimator specifically (typically the treatment effect), regardless of what j is; equal to ssq_b_j when j = 2. NA if 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_type is 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), or NA if neg_ll is non-finite.

hit_iteration_cap

A logical value, mutually exclusive with converged: TRUE iff the optimizer exhausted maxit iterations 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.