tests/testthat/test-edge-cases.R

test_that("loglik_frailty handles small sample size and boundary parameter values safely", {
  set.seed(42)
  time <- c(0.1, 0.2, 0.5, 1.0, 2.0)
  status <- c(1, 0, 1, 1, 0)
  x <- matrix(c(1, 1, 1, 1, 1), ncol = 1) # constant covariate

  ll <- loglik_frailty(c(log(1), log(1), log(0.01), 0), time = time, status = status, x = x,
                       baseline = "weibull", frailty = "gamma")
  expect_true(is.finite(ll))
})

test_that("GL2 parameter reparameterization satisfies 0 < mu <= 1 + theta structurally", {
  theta_val <- 2.0
  for (mu_raw in c(-100, -5, 0, 5, 100)) {
    p_val <- pmin(pmax(stats::plogis(mu_raw), 1e-15), 1.0 - 1e-15)
    mu_val <- (1.0 + theta_val) * p_val
    expect_true(mu_val > 0)
    expect_true(mu_val < (1.0 + theta_val))
  }
})

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.