tests/testthat/test-loglike_faster.R

test_that("loglike_obs_data", {
  par <- c("beta_0" = -2,
           "beta_1" = 1)
  freq <- c(2, 1, 1)
  df <- data.frame(freq = freq,
                   n = c(3, 3, 4),
                   n_pos = c(2,3,1))
  sampled_trees_summary <- data.frame(
    i_pos = c(1, 2, 2),
    n_pos = c(2, 3, 1),
    n = c(3, 3, 4))


  out <- loglike_obs_data(par = par,
                          data = df,
                          sampled_trees_summary,
                          return_neg = FALSE)
  expect_equal(length(out), 1 )

})


test_that("loglike_clust_cond", {
  p_plus <- .4
  p_neg <- .2
  clust_df <- data.frame(i_pos = 1,
                         n_pos = 2,
                         n = 3)
  out <- loglike_clust_cond(p_plus, p_neg,
                            clust_df)
  exp_out <- (.4)^1 *
    (.2)^1 *
    (.6)^2 *
    (.8)^1
  expect_equal(out, log(exp_out))
  ############################
})
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.