Converts a brms-style formula into a structured specification for a two-part hurdle Beta-Binomial model. The fixed effects specified in the formula enter both model margins (extensive and intensive) with separate coefficient vectors \(\alpha\) and \(\beta\).
Value
An S3 object of class "hbb_formula" with components:
responseCharacter. The response variable name.
trialsCharacter. The trials variable name.
fixedCharacter vector of fixed effect term names, excluding the intercept (which is always implicit).
groupCharacter or
NULL. The grouping variable for random effects.randomCharacter vector of random effect terms, or
NULLif no random effects. Contains"1"for intercept-only random effects, or variable names for state-varying coefficients.policyCharacter vector of policy moderator term names, or
NULLif none specified.formulaThe original formula object.
svcLogical.
TRUEif the model includes random slopes (state-varying coefficients), not just a random intercept.
Details
Formula syntax
The left-hand side must specify both the response variable and
the trials variable using the | trials() syntax:
The right-hand side supports four types of terms:
Fixed effects: Standard R formula terms (e.g.,
x1 + x2). An intercept is always included automatically. Usey | trials(n) ~ 1for an intercept-only model.Random intercept:
(1 | group)specifies a random intercept grouped bygroup.State-varying coefficients (SVC):
(x1 + x2 | group)specifies random slopes forx1andx2(plus the implicit random intercept). All random slope variables must also appear as fixed effects.Policy moderators:
state_level(v1 + v2)specifies cross-level interaction terms that predict the random effects. These require that random effects are also specified.
Model mapping
The parsed formula maps to the model as follows:
Fixed effects \(\to\) the \(X\) matrix (with auto-prepended intercept column)
The grouping variable \(\to\) the state index vector
Policy moderators \(\to\) the \(V\) matrix (with auto-prepended intercept column)
Both hurdle margins share the same \(X\) design matrix
See also
validate_hbb_formula() to check a formula against a dataset.
Other formula:
validate_hbb_formula()
Examples
# Intercept-only model
f1 <- hbb_formula(y | trials(n_trial) ~ 1)
f1
#> Hurdle Beta-Binomial Formula
#> ----------------------------
#> Response : y
#> Trials : n_trial
#> Fixed : (intercept only)
#> Random : none
#> Policy : none
#> SVC : FALSE
# Fixed effects only
f2 <- hbb_formula(y | trials(n_trial) ~ poverty + urban)
f2
#> Hurdle Beta-Binomial Formula
#> ----------------------------
#> Response : y
#> Trials : n_trial
#> Fixed : intercept + poverty + urban
#> Random : none
#> Policy : none
#> SVC : FALSE
# Random intercept
f3 <- hbb_formula(y | trials(n_trial) ~ poverty + (1 | state_id))
f3
#> Hurdle Beta-Binomial Formula
#> ----------------------------
#> Response : y
#> Trials : n_trial
#> Fixed : intercept + poverty
#> Random : (1 | state_id ) [random intercept]
#> Policy : none
#> SVC : FALSE
# SVC with policy moderators
f4 <- hbb_formula(
y | trials(n_trial) ~ poverty + urban +
(poverty + urban | state_id) +
state_level(mr_pctile + tiered_reim)
)
f4
#> Hurdle Beta-Binomial Formula
#> ----------------------------
#> Response : y
#> Trials : n_trial
#> Fixed : intercept + poverty + urban
#> Random : (1 + poverty + urban | state_id ) [SVC]
#> Policy : state_level( mr_pctile + tiered_reim )
#> SVC : TRUE