R/inference_switches.R

Defines functions inference_switches

inference_switches <-
function(mu,ksi,randomize,name,index,sequences,nb_tree,list_tree,eig_val, eig_vect, ivp, propinv){
  
  N=ncol(sequences)
  n=length(sequences)
  
  output <- unlist(lapply(1:nb_tree, function (i) LL_tree(mu,symbiont_tree=list_tree[[i]],sequences,n,N,eig_val, eig_vect, ivp, propinv)))
  
  rm(list_tree)
  if (all(is.finite(output))) {
    max_likelihood <- max(-unlist(output))
    likelihood <- -(log(sum(exp(-unlist(output)-max_likelihood)))-log(nb_tree)+max_likelihood)
    if (randomize==F){write.table(data.frame(cbind(round(unlist(output),digits = 5))),file=paste("results/optim_ll_",name,"_",index,"_",ksi,".txt",sep=""),col.names = F,row.names = F,quote=F)}  } else {likelihood <- Inf}
  return(likelihood)
}
BPerezLamarque/HOME documentation built on May 17, 2023, 7:02 a.m.