Skip to contents

Fits 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 X if 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 as ssq_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 as c(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); NA when 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. the j-th diagonal entry of the fitted variance-covariance matrix. In the fallbacks (see Details) it comes from vcov() of the betareg fit or from the OLS variance of fast_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 j argument — provided as a convenience since column 2 is the package's usual treatment-effect position. Identical to ssq_b_j when j = 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.

Examples

set.seed(1)
X = cbind(1, matrix(rnorm(200), 100, 2))
y = plogis(0.5 * X[, 2] - 0.5 * X[, 3] + rnorm(100, sd = 0.3))
fast_beta_regression_with_var(X, y)
#> $b
#> [1]  0.002275246  0.489891724 -0.506027127
#> 
#> $phi
#> [1] 47.21727
#> 
#> $ssq_b_j
#> [1] 0.001196022
#> 
#> $ssq_b_2
#> [1] 0.001196022
#>