Most R packages hardcode specific likelihood models. likelihood.model takes a different approach. Likelihoods are first-class objects that compose, and the framework is generic enough to work with any distribution.
The Interface
A likelihood model is anything implementing these generic methods:
loglik(model, data, params)– log-likelihoodscore(model, data, params)– score function (gradient)hessian(model, data, params)– observed information matrix
That is the interface. If your model implements these three methods, it plugs into the entire MLE stack: optimization, confidence intervals, hypothesis testing, model selection. You do not couple to specific distributions.
Likelihood Contributions
The key class is likelihood_contr_model, a likelihood built from independent contributions:
# Different observation types get different likelihood contributions
model <- likelihood_contr_model(
exact = normal_contrib(),
right_censored = censored_contrib()
)
This handles heterogeneous data in a unified framework. You can mix exact observations, right-censored observations, truncated observations, and different distribution families within one model. Each observation type gets its own likelihood contribution, and they combine additively in log-space.
Why This Design
The i.i.d. assumption decomposes a joint likelihood into additive log-likelihood contributions. That is how MLE actually works. likelihood.model makes this decomposition explicit and compositional.
Likelihood models are objects you manipulate, not function calls buried inside a fitting routine. You can build complex models from simple, independent pieces. You can swap in different contribution types without rewriting the rest of your code. And because the interface is generic, it works with algebraic.mle for fitting, hypothesize for testing, and any optimization backend that speaks the same protocol.
This is the same compositional philosophy as my thesis work on masked failure data. Series systems with masked causes have multiple observation types (masked vs. unmasked, different candidate sets) that each contribute differently to the likelihood. likelihood.model handles that naturally.
R package – MIT licensed – Documentation – GitHub
Discussion