tests/testthat/test-simulate_ruv.R

library(testthat)
library(ggplot2)

context("Simulation with residual unexplained variability")

seed <- 1
source(file.path(getwd(), test_path(), "test-utils.R"))

test_that("Test generated RUV is correct", {
  model <- model_suite$testing$nonmem$advan4_trans4

  ds <- Dataset(500) %>%
    add(Bolus(0, 1000)) %>%
    add(Observations(times = seq(0.1, 24, by = 0.1))) # No predose to avoid zero's

  # Back compute EPS_PROP
  # Y=CP*(EPS_PROP + 1)
  # EPS_PROP = Y/CP - 1

  simulation <- expression(simulate(model = model, dataset = ds, dest = destEngine, seed = seed))
  test <- expression(
    eps <- results$Y / results$CP - 1,
    expect_equal(round(var(eps), 3), 0.025)
  )
  campsis_test(simulation, test, env = environment())
})

Try the campsis package in your browser

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

campsis documentation built on Aug. 5, 2026, 9:07 a.m.