tests/testthat/test-simulate.R

test_that("transition networks can be simulated", {
  set.seed(0)
  # Special case with only one sequence
  expect_error(
    simulate(mock_tna, max_len = 10),
    NA
  )
  expect_error(
    simulate(mock_tna, nsim = 10, max_len = 10),
    NA
  )
})

test_that("missing values can be included", {
  set.seed(0)
  sim <- simulate(mock_tna, nsim = 100, max_len = 10, na_range = c(1, 3))
  nas <- apply(sim, 1L, function(y) sum(is.na(y)))
  expect_true(all(nas %in% c(1, 2, 3)))
})

test_that("transition matrix is recovered", {
  set.seed(0)
  sim <- simulate(mock_tna, nsim = 1e4, max_len = 100)
  tna_sim <- tna(sim)
  expect_equal(mock_tna$weights, tna_sim$weights, tolerance = 0.01)
})

Try the tna package in your browser

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

tna documentation built on June 8, 2025, 10:33 a.m.