R/model.lik.r

Defines functions model.lik

Documented in model.lik

#____________________       Auxiliary functions


#' Auxiliary likelihood Function
#'
#' @description This function computes the likelihood of the model.
#' @param para Value of the model parameters, in the form c(mu, sigma, pi).
#' @param likmat Grid of conditional probabilities for each tumor pair (rows) and each value of xi (columns). 
#' This matrix is generated by the function grid.lik.
#' @param out0 a small value that is used when the likelihood goes to infinite values, posing problem for 
#' the maximization. The corresponding combination of the parameters will thus be excluded from the search.
#' @param xigrid Grid of the values of xi, corresponding to its domain of definition. 
#' @return Return the likelihood value of the model for the given parameters. This likelihood function is 
#' the one that is maximized in the clonal.est function.
#' 
#' @export


# Likelihood function
model.lik <- function(para, likmat, out0, xigrid){
  out <- sum(log( para[3] * likmat[,-1] %*% xidens(para[1],para[2],xigrid)[-1]  * 0.001 + (1-para[3]) * likmat[,1] ) )
  if (!is.finite(out) | out < out0) out <- out0
  out
}

Try the Clonality package in your browser

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

Clonality documentation built on Nov. 8, 2020, 7:45 p.m.