
Fast Weighted Negative Binomial Regression, Estimate Only (C++ Backend)
Source:R/RcppExports.R
fast_neg_bin_weighted_cpp.RdFits the same mean/dispersion-parameterized negative-binomial regression as
fast_neg_bin_cpp (see that page, and
fast_dnbinom_mu_vec_cpp, for the full model), with each
observation's contribution to the log-likelihood multiplied by a
nonnegative row weight weights[i]. Setting all weights to 1 recovers
fast_neg_bin_cpp exactly.
Usage
fast_neg_bin_weighted_cpp(
X,
y,
weights,
warm_start_params = NULL,
smart_cold_start = FALSE,
maxit = 1000L,
eps_f = 1e-08,
eps_g = 1e-06,
fixed_idx = NULL,
fixed_values = NULL,
optimization_alg = "lbfgs",
warm_start_fisher_info = NULL,
estimate_only = FALSE
)Arguments
- X
A numeric matrix of predictors, \(n \times p\).
- y
A numeric (integer-valued) vector of non-negative observed counts, length \(n\).
- weights
A nonnegative numeric vector of length \(n\) giving each row's weight.
- warm_start_params
Optional starting values for coefficients and dispersion. If provided,
smart_cold_startis ignored.- smart_cold_start
Logical. If TRUE, use an initial OLS-based guess when starting from scratch (a "cold start") with no prior knowledge. This is ignored if a warm start is provided.
- maxit
Maximum number of optimizer iterations.
- eps_f
Convergence tolerance on the objective (log-likelihood) value.
- eps_g
Convergence tolerance on the gradient norm.
- fixed_idx
Optional integer indices (into the
c(beta, log(theta))parameter layout) of parameters to hold fixed rather than estimate.- fixed_values
Optional values to fix the parameters named by
fixed_idxat.- optimization_alg
Optimization algorithm:
"lbfgs"(default) or"newton_raphson".- warm_start_fisher_info
Optional initial Fisher Information matrix to warm-start curvature information.
- estimate_only
If TRUE, skip Fisher information calculation.
Value
A list with the same components as fast_neg_bin_cpp:
b, theta_hat, logLik, converged,
iterations, and fisher_information (all reflecting the
weighted log-likelihood).
See also
fast_neg_bin_cpp for the unweighted model and full
documentation.
Examples
X = matrix(rnorm(100), 10, 10)
y = rpois(10, 2)
fast_neg_bin_weighted_cpp(X, y, weights = rep(1, 10))
#> $b
#> [1] -1.10096439 0.12306130 0.55943200 -2.03947942 -0.45032432 0.11545561
#> [7] 1.74134954 0.05038336 -0.64198342 -0.33597138
#>
#> $theta_hat
#> [1] 3128.529
#>
#> $logLik
#> [1] -9.861803
#>
#> $converged
#> [1] TRUE
#>
#> $num_iter
#> [1] 23
#>
#> $hit_iteration_cap
#> [1] FALSE
#>
#> $gradient_norm
#> [1] 0.01118875
#>
#> $min_eigenvalue_information
#> [1] NaN
#>
#> $dispersion_at_poisson_boundary
#> [1] FALSE
#>
#> $fisher_information
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 5.828969e+00 -3.266424e-01 2.876450e+00 4.309775e-01 -0.5423488444
#> [2,] -3.266424e-01 1.378805e+01 8.518026e+00 6.407435e+00 2.2488516937
#> [3,] 2.876450e+00 8.518026e+00 1.119727e+01 6.089860e+00 0.4144641985
#> [4,] 4.309775e-01 6.407435e+00 6.089860e+00 1.726406e+01 -7.1343704016
#> [5,] -5.423488e-01 2.248852e+00 4.144642e-01 -7.134370e+00 9.0521717031
#> [6,] 2.099621e+00 -1.254233e+01 -1.077706e+01 -5.509771e+00 -1.6630103548
#> [7,] -7.496441e-02 6.718588e+00 2.733905e+00 2.304582e+00 3.3765919014
#> [8,] 2.367642e+00 -5.267058e-01 -8.062256e+00 -1.277380e+01 7.2618579931
#> [9,] -4.383028e-02 9.761803e+00 6.520752e+00 -6.535270e+00 11.7038268423
#> [10,] -3.194227e+00 5.269948e-01 -2.393151e+00 -1.185877e+01 4.8554236114
#> [11,] -2.634218e-05 2.091622e-05 -4.606250e-05 -2.914089e-04 0.0002916585
#> [,6] [,7] [,8] [,9] [,10]
#> [1,] 2.099621e+00 -0.074964408 2.367642e+00 -0.0438302789 -3.194227e+00
#> [2,] -1.254233e+01 6.718587681 -5.267058e-01 9.7618033662 5.269948e-01
#> [3,] -1.077706e+01 2.733905189 -8.062256e+00 6.5207520002 -2.393151e+00
#> [4,] -5.509771e+00 2.304582144 -1.277380e+01 -6.5352701013 -1.185877e+01
#> [5,] -1.663010e+00 3.376591901 7.261858e+00 11.7038268423 4.855424e+00
#> [6,] 1.957045e+01 -3.671843732 6.191629e+00 -6.8846969722 -6.470383e-01
#> [7,] -3.671844e+00 9.425941560 9.126470e+00 5.7772940487 6.937392e+00
#> [8,] 6.191629e+00 9.126469884 3.569315e+01 3.3806070299 1.597892e+01
#> [9,] -6.884697e+00 5.777294049 3.380607e+00 22.6824670051 7.425844e+00
#> [10,] -6.470383e-01 6.937391909 1.597892e+01 7.4258440589 2.576703e+01
#> [11,] -9.208585e-05 0.000290825 6.570469e-04 0.0001960197 4.447344e-04
#> [,11]
#> [1,] -2.634218e-05
#> [2,] 2.091622e-05
#> [3,] -4.606250e-05
#> [4,] -2.914089e-04
#> [5,] 2.916585e-04
#> [6,] -9.208585e-05
#> [7,] 2.908250e-04
#> [8,] 6.570469e-04
#> [9,] 1.960197e-04
#> [10,] 4.447344e-04
#> [11,] 2.693209e-03
#>