test_that("Models M1-M4 fit properly on simulated survival data with censoring", { set.seed(42) n <- 50 x_mat <- matrix(rnorm(n), ncol = 1) colnames(x_mat) <- "X1" sim_dat <- r_alpha_power_reg(n = n, par = c(1.5, 1.1), x = x_mat, beta = 0.5, model = "M1", cen_type = "right", cen_rate = 0.1) models <- c("M1", "M2", "M3", "M4") for (m in models) { fit <- fit_alpha_power(sim_dat$time, sim_dat$status, x = x_mat, model = m) expect_s3_class(fit, "alpha_power_fit") expect_true(is.finite(fit$logLik)) expect_true(all(is.finite(fit$coefficients$Estimate))) res <- residuals_alpha_power(fit) expect_true(all(is.finite(res$cox_snell))) expect_true(all(is.finite(res$martingale))) expect_true(all(is.finite(res$deviance))) pred <- predict_alpha_power(fit, type = "survival") expect_true(all(is.finite(pred$survival) & pred$survival >= 0 & pred$survival <= 1)) } }) test_that("Formula interface alpha_power_hazard works cleanly", { set.seed(123) n <- 40 df <- data.frame( time = ralpha_power(n, alpha = 1.5, beta = 0.8), status = sample(c(1, 1, 1, 0), n, replace = TRUE), X1 = rnorm(n) ) fit <- alpha_power_hazard(survival::Surv(time, status) ~ X1, data = df, model = "M1") expect_s3_class(fit, "alpha_power") s <- summary(fit) expect_s3_class(s, "summary.alpha_power") ci <- confint(fit) expect_true(all(is.finite(ci))) })