tests/testthat/test-loglike-faster2.R

test_that("loglike_cond_fast", {
  p_plus <- .6
  p_neg <- .4
  clust_df <- data.frame(i_pos = 2,
                         i_neg = 0,
                         n_pos = 3,
                         n = 4,
                         freq = 2)
  out <- loglike_cond_fast(p_plus, p_neg, clust_df)
  exp_out <- (1 - .6)^3 *
    (1 - .4)^1 *
    .6^2 *
    .4^0 * 2
  expect_equal(out, log(exp_out/2))
  #########################
  p_plus <- .6
  p_neg <- .4
  clust_df <- data.frame(i_pos = 2,
                         n_pos = 3,
                         n = 4,
                         freq = 2)
  out <- loglike_cond_fast(p_plus, p_neg, clust_df)
  exp_out <- (1 - .6)^3 *
    (1 - .4)^1 *
    .6^2 *
    .4^1 * 2
  expect_equal(out, log(exp_out / 2))
#######################################
  p_plus <- .6
  p_neg <- .4
  clust_df <- data.frame(i_pos = 2,
                         n_pos = 3,
                         n = 4,
                         freq = 2)
  out <- loglike_cond_fast(p_plus, p_neg, clust_df,
                           is_truncated = TRUE,
                           w_pos = .75)
  exp_out <- (1 - .6)^3 *
      (1 - .4)^1 *
      .6^2 *
      .4^1 * 2 / (.75 * (.4) + .25 * (.6))
  expect_equal(out, log(exp_out / 2))
  
})
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.