R/core-generics.R
likelihood.model-package.RdThe likelihood.model package provides a framework for likelihood-based
inference. The package is organized in layers:
Core Concept (core-generics.R):
The likelihood_model "concept" – an abstract interface that any model
can implement. At minimum, implement loglik(). Optionally provide
score() and hess_loglik() for analytical derivatives; defaults use
numerical differentiation via numDeriv.
Core Infrastructure:
fisher_mle / fisher_boot: Result objects from MLE fitting, with
methods for coef(), vcov(), confint(), se(), aic(), bic(),
summary().
fit(): Default MLE solver using optim(). Models can override this
with closed-form solutions (see exponential_lifetime for an example).
Fisherian inference: support(), relative_likelihood(),
likelihood_interval(), profile_loglik(), evidence() – pure
likelihood-based inference without probability statements.
lrt(): Likelihood ratio test for nested models.
Model Builders:
likelihood_contr_model: R6 class for building models from heterogeneous observation types (exact, censored, etc.) with dynamic dispatch to type-specific functions.
likelihood_name(): Wraps any standard R distribution (norm, weibull,
exp, ...) with automatic censoring support.
Example Implementations:
Reference implementations showing how to satisfy the likelihood_model
concept with hand-derived analytical solutions:
weibull_uncensored: Weibull with exact observations only. Demonstrates analytical score and hessian (10-100x faster than numerical).
exponential_lifetime: Exponential with right-censoring support.
Demonstrates closed-form MLE (no optim needed), analytical FIM,
and rdata() for Monte Carlo validation.