Examples and Use Cases
This section demonstrates likelihood.model in practical applications.
Example 1: Reliability Analysis
Analyzing component failure times with right-censoring (common in reliability engineering).
library(likelihood.model)
library(algebraic.mle)
# Component failure data (hours to failure)
# Some components are still running at study end (censored)
reliability_data <- data.frame(
hours = c(120, 340, 560, 780, 1000, 1200, 1200, 1200),
failed = c(1, 1, 1, 1, 1, 0, 0, 0) # 0 = still running
)
# Fit Weibull model
model <- likelihood_contr_model(
obs_type = "right_censored",
distribution = weibull_distribution(),
time_col = "hours",
status_col = "failed"
)
fit <- mle(model, data = reliability_data,
start = c(shape = 1, scale = 500))
# Reliability at 1000 hours
shape <- coef(fit)["shape"]
scale <- coef(fit)["scale"]
reliability_1000 <- exp(-(1000/scale)^shape)
cat("R(1000) =", round(reliability_1000, 3))
Example 2: Clinical Trial Survival Analysis
Analyzing time-to-event data from a clinical trial.
# Simulated clinical trial data
trial_data <- data.frame(
patient_id = 1:50,
survival_months = c(
2.3, 5.1, 8.4, 12.0, 15.2, 18.0, 18.0, 18.0, # Treatment group
1.1, 3.2, 4.8, 7.5, 9.0, 11.2, 18.0, 18.0 # Control group
# ... more patients
),
event = c(1, 1, 1, 1, 1, 0, 0, 0,
1, 1, 1, 1, 1, 1, 0, 0),
treatment = rep(c("treatment", "control"), each = 8)
)
# Fit separate models per group
fit_treatment <- mle(
likelihood_contr_model("right_censored", weibull_distribution()),
data = subset(trial_data, treatment == "treatment"),
start = c(shape = 1, scale = 10)
)
fit_control <- mle(
likelihood_contr_model("right_censored", weibull_distribution()),
data = subset(trial_data, treatment == "control"),
start = c(shape = 1, scale = 10)
)
# Compare median survival times
median_treatment <- coef(fit_treatment)["scale"] * log(2)^(1/coef(fit_treatment)["shape"])
median_control <- coef(fit_control)["scale"] * log(2)^(1/coef(fit_control)["shape"])
Example 3: Series System with Masked Failure Causes
When a system fails but the specific component causing failure is unknown (masked data).
This example uses the wei.series.md.c1.c2.c3 package which builds on likelihood.model:
library(wei.series.md.c1.c2.c3)
# System with 3 components, masked failure cause
system_data <- data.frame(
system_id = 1:20,
failure_time = c(100, 150, 200, 180, 220, ...),
candidate_set = list(
c(1, 2), # Could be component 1 or 2
c(2, 3), # Could be component 2 or 3
c(1), # Known to be component 1
c(1, 2, 3), # Any component possible
...
)
)
# Fit the masked data model
fit <- mle_wei_series_md_c1_c2_c3(system_data)
Example 4: Profile Likelihood for Confidence Regions
Computing profile likelihood confidence intervals.
library(likelihood.model)
library(algebraic.mle)
# Fit model
fit <- mle(model, data = data, start = c(shape = 1, scale = 5))
# Profile likelihood for shape parameter
profile_shape <- profile_likelihood(
fit,
parameter = "shape",
range = c(0.5, 3.0),
n_points = 50
)
# Plot profile
plot(profile_shape$values, profile_shape$loglik, type = "l",
xlab = "Shape", ylab = "Profile Log-Likelihood")
abline(h = max(profile_shape$loglik) - qchisq(0.95, 1)/2,
lty = 2, col = "red") # 95% CI threshold
Related Blog Posts
For more detailed discussions and derivations, see the blog posts about likelihood.model.