R/likelihood_orig_p.R

Defines functions likelihood_orig_p

likelihood_orig_p <- function(params, p, data) {
  # browser()
  phi <- params[1, ]
  theta <- params[2, ]
  n00 <- data[1]; n01 <- data[2]; n10 <- data[3]
  n11 <- data[4]; X <- data[5]; Y <- data[6]
  pi <- p * (1 - theta) + (1 - p) * phi

  log_likelihood_1 <- n00 * (log(1 - p) + log(1 - phi))
  log_likelihood_1[is.nan(log_likelihood_1)] <- 0

  log_likelihood_2 <- n01 * (log(1 - p) + log(phi))
  log_likelihood_2[is.nan(log_likelihood_2)] <- 0

  log_likelihood_3 <- n10 * (log(p) + log(theta))
  log_likelihood_3[is.nan(log_likelihood_3)] <- 0

  log_likelihood_4 <- n11 * (log(p) + log(1 - theta))
  log_likelihood_4[is.nan(log_likelihood_4)] <- 0

  log_likelihood_5 <- X * log(pi)
  log_likelihood_5[is.nan(log_likelihood_5)] <- 0

  log_likelihood_6 <- Y * log(1 - pi)
  log_likelihood_6[is.nan(log_likelihood_6)] <- 0

  log_likelihood <-
    log_likelihood_1 + log_likelihood_2 +
    log_likelihood_3 + log_likelihood_4 +
    log_likelihood_5 + log_likelihood_6
  matrix(exp(log_likelihood), ncol = ncol(params))
}
BriceonWiley/IntegratedLikelihood.R documentation built on Aug. 21, 2020, 11 p.m.