
Fast Beta Regression with Variance Calculation (C++ Backend)
Source:R/helper_glm_fit.R, R/RcppExports.R
fast_beta_regression_with_var_cpp.RdFits the same beta regression model as fast_beta_regression_cpp
(see that page for the full model, parameterization, and optimizer contract) and
additionally computes the variance-covariance matrix and standard errors of the
fitted parameters, via the same working-weights (\(X^\top W X\)) curvature
matrix documented there.
Usage
fast_beta_regression_with_var_cpp(
X,
y,
warm_start_beta = NULL,
smart_cold_start = TRUE,
start_phi = 10,
compute_std_errs = TRUE,
fixed_idx = NULL,
fixed_values = NULL,
optimization_alg = "lbfgs",
warm_start_fisher_info = NULL
)Arguments
- X
A numeric matrix of predictors, \(n \times p\).
- y
A numeric vector of responses, strictly in \((0, 1)\).
- warm_start_beta
Optional starting values for coefficients. 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.
- start_phi
Starting value for the precision parameter \(\phi\) (natural scale).
- compute_std_errs
Deprecated; standard errors are always computed by this entry point regardless of this argument's value.
- fixed_idx
Optional integer indices (into the
c(beta, log(phi))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; see
fast_beta_regression_cpp.
Value
A list containing the following components:
- coefficients
A numeric vector of the obtained Poisson regression coefficients.
- phi
The estimated precision parameter phi.
- vcov
The variance-covariance matrix.
- neg_ll
The negative log-likelihood at the final iteration.
- converged
A logical value indicating whether the algorithm converged.
A list with components coefficients (\(\hat\beta\)),
phi (\(\hat\phi\)), neg_loglik, vcov (the full
(p + 1) x (p + 1) parameter variance-covariance matrix), std_errs
(sqrt(diag(vcov))), converged (logical), and
information_invertible (whether the free information block passed
the invertibility check), and
fisher_information (the working-weights curvature matrix vcov was
inverted from).
Details
Variance computation. The fit's working-information matrix
(fit.XtWX, over all p + 1 parameters c(beta, log(phi))) is
restricted to the free (non-fixed_idx) parameters. A FullPivLU
invertibility check guards the same plain matrix inverse used previously, so
invertible fits retain their existing covariance values. A singular or
non-finite free block returns a NaN covariance and standard errors;
callers should check is.finite(vcov) before using its entries.
See also
fast_beta_regression_cpp for the estimate-only variant and
the full model/parameterization documentation;
fast_beta_regression_weighted_cpp for the row-weighted
estimate-only variant.
Examples
X = matrix(rnorm(100), 10, 10)
y = runif(10)
fast_beta_regression_with_var_cpp(X, y)
#> $coefficients
#> [1] -55.83039 -111.85338 254.11466 36.35758 -275.89588 -53.31728
#> [7] 111.83331 -76.94184 -407.27657 -60.45378
#>
#> $phi
#> [1] 228619673178
#>
#> $neg_loglik
#> [1] -127.2674
#>
#> $vcov
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] -6.217188e-08 -1.248597e-07 2.864423e-07 4.073676e-08 -3.110189e-07
#> [2,] -1.248597e-07 -2.507377e-07 5.752312e-07 8.180236e-08 -6.245863e-07
#> [3,] 2.864423e-07 5.752312e-07 -1.319566e-06 -1.876419e-07 1.432787e-06
#> [4,] 4.073676e-08 8.180236e-08 -1.876419e-07 -2.667153e-08 2.037452e-07
#> [5,] -3.110189e-07 -6.245863e-07 1.432787e-06 2.037452e-07 -1.555712e-06
#> [6,] -6.024826e-08 -1.209776e-07 2.775224e-07 3.946146e-08 -3.013304e-07
#> [7,] 1.254513e-07 2.519368e-07 -5.779072e-07 -8.217701e-08 6.274909e-07
#> [8,] -8.397318e-08 -1.686409e-07 3.868780e-07 5.501074e-08 -4.200829e-07
#> [9,] -4.585204e-07 -9.208006e-07 2.112308e-06 3.003768e-07 -2.293543e-06
#> [10,] -6.726702e-08 -1.350847e-07 3.098896e-07 4.406141e-08 -3.364842e-07
#> [11,] 1.653353e-04 3.320560e-04 -7.617187e-04 -1.083037e-04 8.271053e-04
#> [,6] [,7] [,8] [,9] [,10]
#> [1,] -6.024826e-08 1.254513e-07 -8.397318e-08 -4.585204e-07 -6.726702e-08
#> [2,] -1.209776e-07 2.519368e-07 -1.686409e-07 -9.208006e-07 -1.350847e-07
#> [3,] 2.775224e-07 -5.779072e-07 3.868780e-07 2.112308e-06 3.098896e-07
#> [4,] 3.946146e-08 -8.217701e-08 5.501074e-08 3.003768e-07 4.406141e-08
#> [5,] -3.013304e-07 6.274909e-07 -4.200829e-07 -2.293543e-06 -3.364842e-07
#> [6,] -5.835047e-08 1.215464e-07 -8.137923e-08 -4.442483e-07 -6.517760e-08
#> [7,] 1.215464e-07 -2.530775e-07 1.694346e-07 9.250918e-07 1.357184e-07
#> [8,] -8.137923e-08 1.694346e-07 -1.133869e-07 -6.192952e-07 -9.083899e-08
#> [9,] -4.442483e-07 9.250918e-07 -6.192952e-07 -3.381287e-06 -4.960604e-07
#> [10,] -6.517760e-08 1.357184e-07 -9.083899e-08 -4.960604e-07 -7.276489e-08
#> [11,] 1.602565e-04 -3.335670e-04 2.232100e-04 1.219330e-03 1.788385e-04
#> [,11]
#> [1,] 0.0001653353
#> [2,] 0.0003320560
#> [3,] -0.0007617187
#> [4,] -0.0001083037
#> [5,] 0.0008271053
#> [6,] 0.0001602565
#> [7,] -0.0003335670
#> [8,] 0.0002232100
#> [9,] 0.0012193295
#> [10,] 0.0001788385
#> [11,] -0.2197364468
#>
#> $std_errs
#> [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
#>
#> $information_invertible
#> [1] TRUE
#>
#> $converged
#> [1] FALSE
#>
#> $num_iter
#> [1] 1000
#>
#> $hit_iteration_cap
#> [1] FALSE
#>
#> $gradient_norm
#> [1] NaN
#>
#> $min_eigenvalue_information
#> [1] NaN
#>
#> $fisher_information
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 8.672470e+11 -2.190599e+11 4.321716e+10 -2.219666e+11 -2.084816e+11
#> [2,] -2.190599e+11 2.442975e+11 1.474870e+10 -3.787606e+10 -1.517448e+10
#> [3,] 4.321716e+10 1.474870e+10 7.378529e+11 -2.761832e+11 -6.011291e+10
#> [4,] -2.219666e+11 -3.787606e+10 -2.761832e+11 3.720351e+11 1.540186e+11
#> [5,] -2.084816e+11 -1.517448e+10 -6.011291e+10 1.540186e+11 3.205095e+11
#> [6,] 2.868647e+11 -1.015707e+11 -1.728329e+10 -1.716611e+09 -6.985003e+10
#> [7,] -7.194255e+10 -9.873166e+10 -7.108883e+10 5.833609e+10 9.139662e+10
#> [8,] -8.503299e+10 -1.953403e+10 -1.567645e+11 8.462209e+10 1.155524e+11
#> [9,] 5.239667e+10 -1.988048e+10 4.524140e+11 -2.216654e+11 -2.006659e+11
#> [10,] -2.355436e+10 -7.422379e+10 1.800844e+11 1.282500e+11 3.283893e+10
#> [11,] -1.635101e+04 5.503996e+02 -1.003498e+04 9.450008e+03 9.116706e+03
#> [,6] [,7] [,8] [,9] [,10]
#> [1,] 2.868647e+11 -7.194255e+10 -8.503299e+10 5.239667e+10 -2.355436e+10
#> [2,] -1.015707e+11 -9.873166e+10 -1.953403e+10 -1.988048e+10 -7.422379e+10
#> [3,] -1.728329e+10 -7.108883e+10 -1.567645e+11 4.524140e+11 1.800844e+11
#> [4,] -1.716611e+09 5.833609e+10 8.462209e+10 -2.216654e+11 1.282500e+11
#> [5,] -6.985003e+10 9.139662e+10 1.155524e+11 -2.006659e+11 3.283893e+10
#> [6,] 2.184145e+11 -3.800770e+10 3.449403e+10 -1.689430e+10 -2.271004e+10
#> [7,] -3.800770e+10 1.502179e+11 4.526684e+10 -2.869832e+10 1.308288e+10
#> [8,] 3.449403e+10 4.526684e+10 1.754539e+11 -1.506423e+11 -1.743443e+11
#> [9,] -1.689430e+10 -2.869832e+10 -1.506423e+11 4.058813e+11 9.153157e+10
#> [10,] -2.271004e+10 1.308288e+10 -1.743443e+11 9.153157e+10 4.906945e+11
#> [11,] -8.968773e+03 -2.111567e+03 1.651672e+04 -1.048676e+04 1.083451e+03
#> [,11]
#> [1,] -16351.014499
#> [2,] 550.399596
#> [3,] -10034.976598
#> [4,] 9450.008105
#> [5,] 9116.705913
#> [6,] -8968.772674
#> [7,] -2111.566718
#> [8,] 16516.720797
#> [9,] -10486.764827
#> [10,] 1083.451445
#> [11,] 4.554915
#>