## Simulate survival data with covariates
set.seed(1234)
n <- 1000
t1 <- rnorm(n)
t2 <- rbinom(n, 1, 0.5)
## Generate survival times with Weibull-like structure
lambda <- exp(0.5 * t1 + 0.3 * t2)
yraw <- rexp(n, rate = 1/lambda)
## Introduce right-censoring
status <- rbinom(n, 1, 0.75)
y <- ifelse(status, yraw, runif(1, 0, yraw))
## Example of using dispersion function
mu <- mean(y)
order_indices <- seq_along(y)
weights <- rep(1, n)
## Estimate dispersion
dispersion_est <- weibull_dispersion_function(
mu = mu,
y = y,
order_indices = order_indices,
family = weibull_family(),
observation_weights = weights,
status = status
)
print(dispersion_est)
Run the code above in your browser using DataLab