A 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)

Arguments

ob_col

The name of the column containing observation times.

censor_col

Optional column name indicating censoring status. When provided, values should be "exact" for uncensored observations and "right" for right-censored observations. When NULL, all observations are treated as exact.

Value

An exponential_lifetime likelihood model object

Examples

# 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