Back to algebraic.mle

Documentation

API reference and core concepts for algebraic.mle.

API Documentation

The algebraic.mle package provides an algebra over Maximum Likelihood Estimators (MLEs). It enables manipulation and inference on fitted models through a consistent, composable interface.

Core Class: mle

The central abstraction is the mle S3 class, which wraps fitted model results with statistical properties.

Constructors

FunctionDescription
mle()Create an MLE object from components (theta, variance, log-likelihood)
mle_numerical()Wrap results from optim() or similar numerical optimizer
mle_boot()Create a bootstrap MLE for uncertainty quantification
mle_weighted()Create a weighted MLE from multiple estimates

Creating an MLE

library(algebraic.mle)

# From optim() results
result <- optim(par = c(0, 1), fn = negloglik, hessian = TRUE)
fit <- mle_numerical(result)

# From explicit components
fit <- mle(
  theta.hat = c(mu = 2.5, sigma = 1.2),
  loglike = -150.3,
  sigma = solve(-result$hessian),  # Variance-covariance matrix
  nobs = 100
)

Statistical Properties

The mle class provides methods for common statistical operations:

Point Estimates

FunctionDescription
params(mle)Extract parameter estimates (θ̂)
coef(mle)Alias for params()
loglik_val(mle)Extract log-likelihood value

Uncertainty Quantification

FunctionDescription
vcov(mle)Variance-covariance matrix of estimates
se(mle)Standard errors (sqrt of diagonal of vcov)
confint(mle)Confidence intervals (default 95%)
bias(mle)Bias estimate (if available)

Model Diagnostics

FunctionDescription
aic(mle)Akaike Information Criterion
nobs(mle)Number of observations
summary(mle)Print comprehensive summary

Working with Estimates

Confidence Intervals

# 95% confidence interval (default)
confint(fit)

# 99% confidence interval
confint(fit, level = 0.99)

# From variance-covariance matrix
confint_from_sigma(theta.hat, sigma, level = 0.95)

Information Criteria

# Compare models using AIC
aic(model1)
aic(model2)

# Lower AIC indicates better fit (penalizing complexity)

Marginal and Transformed Estimates

Extracting Marginals

# Extract marginal distribution for a single parameter
marginal_mu <- marginal(fit, "mu")

# Work with the marginal
confint(marginal_mu)

Transformations

The delta method enables inference on transformations of parameters:

# If fit has parameters (mu, sigma), compute mean lifetime = mu
# For exponential rate lambda, mean = 1/lambda
expectation(fit)  # Uses the appropriate transformation

Bootstrap Methods

When asymptotic normality is questionable, use bootstrap:

# Create bootstrap MLE
boot_fit <- mle_boot(data, fit_function, R = 1000)

# Bootstrap confidence intervals
confint(boot_fit, type = "bca")  # Bias-corrected accelerated
confint(boot_fit, type = "perc") # Percentile method

# Check for bias
bias(boot_fit)

Integration with likelihood.model

algebraic.mle is designed to work with likelihood.model:

library(likelihood.model)
library(algebraic.mle)

# Build a 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))

# Use algebraic.mle methods on the result
confint(fit)
aic(fit)
summary(fit)

Full Reference

For complete API documentation with all function signatures: