API Documentation
The likelihood.model package provides a modular framework for constructing likelihood functions from independent contributions. This page summarizes the core API.
Core Class: likelihood_contr_model
The central abstraction is the likelihood_contr_model S3 class, which represents a likelihood model built from independent contributions.
Constructor
likelihood_contr_model(
obs_type, # Type of observation: "exact", "right_censored", etc.
distribution, # Distribution object (e.g., weibull_distribution())
data = NULL, # Optional data frame
...
)
Generic Functions
The package implements several generic functions that any likelihood model must support:
| Function | Description |
|---|---|
loglik(model, theta, data) | Compute log-likelihood at parameter values |
score(model, theta, data) | Compute score function (gradient) |
fisher_info(model, theta, data) | Compute Fisher information matrix |
obs_loglik(model, theta, data) | Per-observation log-likelihood contributions |
Observation Types
Different observation types contribute differently to the likelihood:
Exact Observations
For fully observed data, the contribution is the log-density:
Right-Censored Observations
For right-censored data (e.g., survival analysis), the contribution uses the survival function:
where is the event indicator.
Interval-Censored Observations
For interval-censored data, the contribution is:
Distribution Interface
Distribution objects must implement:
# Density function
pdf(dist, x, theta)
# Cumulative distribution function
cdf(dist, x, theta)
# Survival function
sf(dist, x, theta)
# Hazard function (optional)
hf(dist, x, theta)
Built-in Distributions
weibull_distribution()- Two-parameter Weibullexponential_distribution()- Exponential (special case of Weibull)lognormal_distribution()- Log-normal distribution
Integration with algebraic.mle
The package is designed to work seamlessly with algebraic.mle:
library(likelihood.model)
library(algebraic.mle)
# Create likelihood model
model <- likelihood_contr_model(
obs_type = "right_censored",
distribution = weibull_distribution()
)
# Fit using MLE
fit <- mle(model, data = my_data, start = c(shape = 1, scale = 1))
# Access results
coef(fit) # Parameter estimates
vcov(fit) # Variance-covariance matrix
confint(fit) # Confidence intervals
Full Reference
For complete API documentation, including all function signatures and examples, see the pkgdown documentation.