Computes residuals for the hurdle Beta-Binomial model. Two types are supported:
Arguments
- object
An object of class
"hbb_fit"returned byhbb.- type
Character string:
"response"(default) or"pearson".- ...
Currently unused; included for S3 method consistency.
Details
"response"Raw residuals on the proportion scale: \(r_i = y_i / n_i - \hat{q}_i \hat{\mu}_i\).
"pearson"Pearson residuals standardised by the model-implied standard deviation (count scale): $$ r_i^P = \frac{y_i - n_i \hat{q}_i \hat{\mu}_i} {\sqrt{\widehat{\mathrm{Var}}(Y_i)}}, $$ where \(\widehat{\mathrm{Var}}(Y_i)\) is computed via
hurdle_varianceusing \((n_i, \hat{q}_i, \hat\mu_i, \hat\kappa)\). Under correct model specification, Pearson residuals have approximately mean zero and variance one.
Numerical stability (Pearson residuals)
Several guards are applied to prevent division by zero or NaN:
\(\hat\mu_i\) is clamped to \((\varepsilon,\; 1 - \varepsilon)\) where \(\varepsilon = \sqrt{\mathtt{.Machine\$double.eps}}\) (\(\approx 1.49 \times 10^{-8}\)).
\(\hat{q}_i\) is clamped to \([\varepsilon,\; 1]\). (\(q = 0\) yields \(\mathrm{Var}[Y] = 0\), making Pearson undefined.)
\(\hat{\kappa}\) is clamped to \(\le 10^{15}\).
The hurdle variance is floored at
.Machine$double.epsto prevent division by zero.Non-finite residuals are replaced with
NAand a warning is issued.