R/loglik.2.R

Defines functions loglik.2

loglik.2 <- function(pa,z,f) {
  # we have to do some work to avoid negative arguments to the log function which can arise due to rounding if there is a zero homozygote count.
  paa <- pa^2 + pa*(1-pa)*f
  pab <- 2*pa*(1-pa)*(1-f)
  pbb <- (1-pa)^2 + pa*(1-pa)*f
  pvec <- c(paa,pab,pbb)
  ind <- !(z==0)
  logvec <- log(pvec[ind])
  loglik0 <- sum(z[ind]*logvec)
  nparam0 <- 2
  res <- c(loglik0,nparam0)
  return(res)
}

Try the HardyWeinberg package in your browser

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

HardyWeinberg documentation built on May 29, 2024, 6:17 a.m.