Creates a likelihood model based on R's distribution naming convention,
where distributions have functions named d<name> (PDF), p<name> (CDF),
q<name> (quantile), and r<name> (random generation).
likelihood_name(dist_name, ob_col, censor_col = NULL, ob_col_upper = NULL)The name of the distribution (e.g., "norm", "weibull", "exp")
The name of the column containing observations (lower bound for interval-censored data)
The name of the column containing censoring type, or NULL for all exact observations. Valid values: "exact", "left", "right", "interval", or NA.
The name of the column containing the upper bound for interval-censored observations, or NULL if no interval censoring is used.
A likelihood model object
The model automatically handles exact and censored observations:
Exact: uses PDF (d
Left-censored: uses CDF (p
Right-censored: uses survival function (1 - CDF)
# Simple case - all exact observations
model <- likelihood_name("norm", ob_col = "x")
df <- data.frame(x = rnorm(100))
ll <- loglik(model)
ll(df, c(mean = 0, sd = 1))
#> [1] -151.3702
# With censoring
model <- likelihood_name("weibull", ob_col = "time", censor_col = "status")
df <- data.frame(time = rweibull(100, 2, 1),
status = sample(c("exact", "right"), 100, replace = TRUE))
# With interval censoring
model <- likelihood_name("norm", ob_col = "x", censor_col = "censor",
ob_col_upper = "x_upper")