tests/testthat/test-fit.R

test_that("fit_frailty fits all 10 combinations on simulated data without error", {
  set.seed(42)
  n <- 80
  x <- matrix(rnorm(n), ncol = 1)
  time <- rexp(n, rate = 0.2) + 0.1
  status <- sample(c(0, 1), n, replace = TRUE, prob = c(0.3, 0.7))

  combos <- list(
    list(b = "weibull", f = "none"),
    list(b = "weibull", f = "gamma"),
    list(b = "weibull", f = "ig"),
    list(b = "weibull", f = "gl1"),
    list(b = "weibull", f = "gl2"),
    list(b = "gw", f = "none"),
    list(b = "gw", f = "gamma"),
    list(b = "gw", f = "ig"),
    list(b = "gw", f = "gl1"),
    list(b = "gw", f = "gl2")
  )

  for (item in combos) {
    fit <- fit_frailty(time = time, status = status, x = x, baseline = item$b, frailty = item$f)
    expect_s3_class(fit, "multifrailty_fit")
    expect_true(fit$converged, label = paste("Convergence for", item$b, item$f))
    expect_true(is.finite(fit$logLik), label = paste("Finite logLik for", item$b, item$f))
    expect_true(all(is.finite(fit$coefficients$Estimate)), label = paste("Finite estimates for", item$b, item$f))
  }
})

Try the MultiFrailty package in your browser

Any scripts or data that you put into this service are public.

MultiFrailty documentation built on Aug. 8, 2026, 1:07 a.m.