
Fast Beta Regression with Variance Calculation (R Wrapper)
Source:R/helper_glm_fit.R
fast_beta_regression_with_var.RdFits the same beta regression model as fast_beta_regression (see
fast_beta_regression_cpp for the full model equation and
parameterization) and additionally reports the estimated variance of a
caller-selected coefficient, extracted from the fitted parameter
variance-covariance matrix (see
fast_beta_regression_with_var_cpp for how that matrix is computed
and its plain-inverse numerical caveat on rank-deficient designs).
Usage
fast_beta_regression_with_var(
X,
y,
start_phi = 10,
j = 2,
optimization_alg = "lbfgs",
warm_start_beta = 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, with values strictly between 0 and 1. See
sanitize_beta_response()(internal) for boundary-value handling.- start_phi
A numeric value, the starting value for the precision parameter phi. Defaults to 10.
- j
The 1-based index (into
X's columns, i.e. into \(\beta\)) of the coefficient to report the variance of asssq_b_j. Defaults to 2 (the package's usual convention for the treatment-effect column when an intercept occupies column 1).- optimization_alg
Optimization algorithm:
"lbfgs"(default) or"newton_raphson"; see.normalize_optimizer_algorithm.- warm_start_beta
Optional starting values for coefficients \(\beta\).
- warm_start_fisher_info
Optional initial information matrix for the first optimizer iteration, passed to the C++ fitter. It must be
(ncol(X) + 1) x (ncol(X) + 1), ordered asc(beta, log(phi)).NULL(the default) starts from the fitter's own initial curvature.
Value
A list containing the following components:
- b
A numeric vector of the estimated beta regression coefficients \(\hat\beta\) (logit-of-mean scale).
- phi
The estimated precision parameter \(\hat\phi\) (natural scale);
NAwhen the final OLS-on-logit(y)fallback was used (see Details).- ssq_b_j
The estimated variance (squared standard error) of the
j-th coefficient, \(\widehat{\mathrm{Var}}(\hat\beta_j)\), i.e. thej-th diagonal entry of the fitted variance-covariance matrix. In the fallbacks (see Details) it comes fromvcov()of the betareg fit or from the OLS variance offast_ols_with_var_cpp, respectively.- ssq_b_2
The estimated variance of the second coefficient specifically (\(\widehat{\mathrm{Var}}(\hat\beta_2)\)), regardless of the
jargument — provided as a convenience since column 2 is the package's usual treatment-effect position. Identical tossq_b_jwhenj = 2.
Details
The primary implementation uses a C++ backend. If that fails, the function falls back
to betareg, which is listed in Suggests and is not installed automatically
with EDI. If betareg is also unavailable, a final fallback of OLS on
logit(y) is used. Install betareg manually to
enable the intermediate fallback.