tests/testthat/test_lifetime.R

test_that("lifetime_dist computes quantiles and curves accurately", {
  data(laser)
  fit_gam <- igp_fit(laser, time_col = "t", deg_col = "increase", unit_col = "unit", frailty = "gamma")
  
  lt <- lifetime_dist(fit_gam, threshold = 10, probs = c(0.01, 0.05, 0.1, 0.5, 0.8))
  expect_s3_class(lt, "lifetime_dist")
  expect_equal(lt$threshold, 10)
  expect_equal(nrow(lt$quantiles), 5)
  expect_equal(unname(round(lt$quantiles$Estimate[lt$quantiles$Quantile == "t0.5"], 2)), 4.94)
  expect_true(all(lt$quantiles$Estimate > 0))
  expect_true(all(lt$quantiles$`CI Lower` < lt$quantiles$`CI Upper`))
  
  # Curve
  expect_true(all(lt$curve$CDF >= 0 & lt$curve$CDF <= 1))
  expect_true(all(lt$curve$PDF >= 0))
  expect_true(all(lt$curve$Survival >= 0 & lt$curve$Survival <= 1))
})

Try the IGPFrailty package in your browser

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

IGPFrailty documentation built on Aug. 25, 2026, 9:08 a.m.