feat(continuous): add a zero-one-inflated beta family - #55
Merged
Conversation
Proportion data is frequently recorded with exact zeros and exact ones, which a beta likelihood cannot represent: its density vanishes at both endpoints, so boundary observations have to be nudged inward or dropped. `ZeroOneInflatedBeta(mu, phi, zoi, coi)` mixes point masses at 0 and 1 with a beta on the open interval. `zoi` is the probability that an observation sits at an endpoint and `coi` the probability that such an endpoint is 1, so `P(0) = zoi (1 - coi)`, `P(1) = zoi coi`, and the remaining mass carries `Beta(mu phi, (1 - mu) phi)`. The continuous part uses the mean-precision parameterisation, leaving `mu` the mean of the beta component and `phi` its precision. The family registers in the compiler prelude as `ZeroOneInflatedBeta` and in the formula frontend as `zero_one_inflated_beta`, with a logit link on the mean and on both inflation probabilities and a log link on the precision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a zero-one-inflated beta likelihood so proportion data with exact zeros and exact ones can be modelled directly, rather than nudged inward or dropped.
Motivation
Rates, shares, and probabilities are routinely recorded with observations sitting exactly on 0 or 1. A beta likelihood cannot represent them: its density vanishes at both endpoints. The usual workarounds either perturb the data or discard the boundary cases, both of which change the inference. A zero-one-inflated beta puts explicit point masses at the endpoints and keeps a beta on the interior.
Changes
continuous/:ZeroOneInflatedBeta(mu, phi, zoi, coi)mixes point masses at 0 and 1 with a beta on the open interval, soP(0) = zoi (1 - coi),P(1) = zoi coi, and the remaining mass carriesBeta(mu phi, (1 - mu) phi). The continuous part uses the mean-precision parameterisation, leavingmuthe mean of the beta component andphiits precision. AConditionalZeroOneInflatedBetaaccompanies it for[role=kernel]declarations.dsl/compiler/: the family registers in the prelude asZeroOneInflatedBeta, and the inlineobserve ... <- ZeroOneInflatedBeta(...)surface is wired.formulas/: the formula frontend names itzero_one_inflated_beta, with a logit link on the mean and on both inflation probabilities and a log link on the precision.API impact
Tests
tests/test_zip_hurdle_mixture.pycovering the two endpoint masses against their closed forms, the interior density against a scaled beta, normalisation (the masses plus the integral over the open interval sum to 1), and batch broadcasting. The registry test now also assertsZeroOneInflatedBetais present.ruff checkandruff format --checkpass.pyrightreports 0 errors on the changed modules.tests/test_zip_hurdle_mixture.pypasses (13 tests); the formula / family / registry selection passes (233 tests).pytest -xnot run on this branch.Documentation
CHANGELOG.mdanddocs/developer/changelog.mdcarry a0.17.0entry.docs/added for the family.Checklist
Note on versioning
pyproject.tomlis bumped0.16.0->0.17.0for the additive family. Worth a look: the transpile line of work carries its own0.17.0.dev0, so whoever cuts the release should confirm both land under the same number.