R/example-exponential.R
exponential_lifetime.RdA likelihood model for the Exponential(lambda) distribution with optional right-censoring. This is a reference implementation demonstrating:
Closed-form MLE: Overrides fit() to compute lambda_hat = d/T
directly, bypassing optim entirely.
Analytical derivatives: score, Hessian, and FIM in closed form.
Right-censoring: Natural handling via the sufficient statistic (d, T) where d = number of exact observations and T = total time.
rdata() method: For Monte Carlo validation and FIM estimation.
The log-likelihood is: $$\ell(\lambda) = d \log \lambda - \lambda T$$ where d is the number of exact (uncensored) observations and T is the total observation time (sum of all times, whether censored or not).
exponential_lifetime(ob_col, censor_col = NULL)An exponential_lifetime likelihood model object
# Uncensored exponential data
model <- exponential_lifetime("t")
df <- data.frame(t = rexp(100, rate = 2))
mle <- fit(model)(df)
coef(mle) # should be close to 2
#> lambda
#> 2.36361
# Right-censored data
model_c <- exponential_lifetime("t", censor_col = "status")
df_c <- data.frame(
t = c(rexp(80, 2), rep(0.5, 20)),
status = c(rep("exact", 80), rep("right", 20))
)
mle_c <- fit(model_c)(df_c)
coef(mle_c)
#> lambda
#> 1.635568