tests/testthat/test-pSizeAtGenSwitch1.R

test_that("pSizeAtGenSwitch1() matches brute-force calculation", {
  pfs1 <- pSizeAtGenSwitch1(g=1, n=1, j=4, R0=1.2, k0=0.33, Rc=0.9, kc=0.8)
  pfs2 <- pSizeAtGenSwitch1(g=2, n=1, j=4, R0=1.2, k0=0.33, Rc=0.9, kc=0.8)
  pfs3 <- pSizeAtGenSwitch1(g=3, n=1, j=4, R0=1.2, k0=0.33, Rc=0.9, kc=0.8)
  
  d0 <- dnbinom(0:3, mu=1.2, size=0.33)
  dc <- dnbinom(0:2, mu=0.9, size=0.8)
  dnb1 <- d0[4]
  dnb2 <- d0[3] * dc[2] * dc[1] * 2 + d0[2] * dc[3]
  dnb3 <- d0[2] * dc[2]^2
  
  expect_equal(pfs1, dnb1, tolerance = sqrt(.Machine$double.eps))
  expect_equal(pfs2, dnb2, tolerance = sqrt(.Machine$double.eps))
  expect_equal(pfs3, dnb3, tolerance = sqrt(.Machine$double.eps))
})

Try the branchingprocess package in your browser

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

branchingprocess documentation built on June 8, 2025, 11:35 a.m.