tests/testthat/test-loglike-doubly-trunc.R

test_that("math is hard -- get_cond_p", {
  
  ## GENERATOR INFECTS EVERYONE
  x0 <- 0
  n0 <- 3
  n <- 4
  n_pos <- 0
  i_pos <- 0
  i_neg <- 3
  p_plus <- .6
  p_neg <- .3
  
  out <- get_cond_p(x0, n0,
                    n, n_pos,
                    i_pos, i_neg,
                    p_plus, p_neg)
  exp_out <- 1
  expect_equal(out, exp_out)
  ####################################3
  ## GENERATOR INFECTS all but one, which was a positive transmission
  ## Remaining people are all positive
  x0 <- 0
  n0 <- 2
  n <- 4
  n_pos <- 3
  i_pos <- 1
  i_neg <- 2
  p_plus <- .6
  p_neg <- .3
  
  out <- get_cond_p(x0, n0,
                    n, n_pos,
                    i_pos, i_neg,
                    p_plus, p_neg)
  exp_out <- 1
  expect_equal(out, exp_out)
  ####################################3
  ## GENERATOR INFECTS all but one, which was a negative transmission
  ## Remaining people are all negative
  x0 <- 0
  n0 <- 2
  n <- 4
  n_pos <- 0
  i_pos <- 0
  i_neg <- 3
  p_plus <- .6
  p_neg <- .3
  
  out <- get_cond_p(x0, n0,
                    n, n_pos,
                    i_pos, i_neg,
                    p_plus, p_neg)
  exp_out <- 1
  expect_equal(out, exp_out)
  ####################################3
  ## GENERATOR INFECTS all but one, which was a negative transmission
  ## Remaining people are combo of neg/pos
  x0 <- 0
  n0 <- 2
  n <- 4
  n_pos <- 1
  i_pos <- 0
  i_neg <- 3
  p_plus <- .6
  p_neg <- .3
  
  out <- get_cond_p(x0, n0,
                    n, n_pos,
                    i_pos, i_neg,
                    p_plus, p_neg)
  num <- p_plus^0 * p_neg
  denom <- (p_neg) + p_plus
  exp_out <- num /denom
  expect_equal(out, exp_out)
  ## GENERATOR INFECTS all but one, which was a positive transmission
  ## Remaining people are combo of neg/pos
  x0 <- 0
  n0 <- 2
  n <- 4
  n_pos <- 1
  i_pos <- 1
  i_neg <- 2
  p_plus <- .6
  p_neg <- .3
  
  out <- get_cond_p(x0, n0,
                    n, n_pos,
                    i_pos, i_neg,
                    p_plus, p_neg)
  num <- p_plus^1 * p_neg^0
  denom <- (p_neg) + p_plus
  exp_out <- num /denom
  expect_equal(out, exp_out)
  
  
 })
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.