Skip to main content

likelihood.model: Composable Statistical Inference in R

Most R packages hardcode specific likelihood models. likelihood.model provides a generic framework where likelihoods are first-class composable objects—designed to work seamlessly with algebraic.mle for maximum likelihood estimation.

The Core Concept

A likelihood model is anything implementing these generic methods:

  • loglik(model, data, params) - Log-likelihood
  • score(model, data, params) - Score function (gradient)
  • hessian(model, data, params) - Observed information matrix

This interface lets you compose likelihood models, swap implementations, and integrate with optimization algorithms—without coupling 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 (exact + censored, multiple distributions) in a unified framework.

Why This Matters

1. Flexibility: Mix observation types (exact, censored, truncated) within one model

2. Composability: Likelihood models are objects you can manipulate, not just function calls

3. Interoperability: Designed to work with algebraic.mle for robust MLE

4. Generality: Works with any distribution—specify contributions, not hardcoded models

Connection to My Research

This embodies the same compositional philosophy as my thesis work on masked failure data: build complex models from simple, independent contributions. The i.i.d. assumption decomposes into additive log-likelihood contributions, which is how MLE actually works under the hood.

R package • MIT licensed • DocumentationGitHub

Discussion