Survival analysis usually makes you pick from a catalog. Weibull, exponential, log-normal. You choose the family, estimate the parameters, and hope the model fits. flexhaz flips this around. You specify the hazard function directly, and the package computes everything else.
How It Works
Instead of choosing Weibull(shape, scale), you write:
h <- function(t, x) exp(b0 + b1*x + b2*t) # Your hazard function
model <- dfr_dist(hazard = h)
The package computes survival functions, cumulative hazards, quantiles, and sampling from your custom hazard. You get a full distributional object without committing to a named family.
Why This Is Useful
You are not constrained to parametric families. Want a bathtub curve? Multiple failure-rate peaks? Time-varying covariate effects? Just write the hazard function. No need to force reality into exponential or Weibull boxes.
Covariates can depend on anything:
h <- function(t, age, treatment) {
baseline * exp(beta_age*age + beta_tx*treatment + gamma*t)
}
And it integrates with the rest of the MLE stack. flexhaz works with algebraic.mle for parameter estimation and likelihood.model for likelihood contributions.
Constraints
Your hazard function needs to satisfy two things:
- Non-negative:
h(t, x) >= 0for all t, x - Eventual failure: cumulative hazard goes to infinity as t goes to infinity
That is it. Those are the only requirements for a valid hazard function. The package handles deriving the survival function, density, CDF, and quantile function from the hazard you provide.
Context
This generalizes my thesis work on masked failure data, where I used Weibull and exponential distributions. With flexhaz, you are not limited to parametric families. You specify the actual failure mechanism, and the math adapts.
R package – Works with algebraic.mle – Documentation – GitHub
Discussion