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 Fisher Information matrix, used to warm-start curvature information for the optimizer.

Value

A list containing the following components:

b

A numeric vector of the estimated beta regression coefficients \(\hat\beta\) (logit-of-mean scale).

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 vcov. NA if the primary C++ fit failed and a fallback stage without a variance estimate was used (see Details).

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

X = matrix(rnorm(100), 10, 10)
y = runif(10)
fast_beta_regression_with_var(X, y)
#> $b
#>  [1]  2.144725 -9.135211  2.826760  5.201531 -4.329368 -3.063817  3.729248
#>  [8] -1.530985  1.355229  7.844373
#> 
#> $phi
#> [1] 106404139112
#> 
#> $ssq_b_j
#> [1] -4.095376e-09
#> 
#> $ssq_b_2
#> [1] -4.095376e-09
#>