R/BIC_Mk.R

Defines functions BIC_Mk

Documented in BIC_Mk

BIC_Mk = function(seq, E, mu, Ptrans, k){

  S = length(E)
  if(dim(Ptrans)[1] != S ^ k || dim(Ptrans)[2] != S){
    stop("The size of the matrix Ptrans must be equal to SxS with S = length(E)")
  }

  if( !is.matrix(Ptrans) ){
    stop("The parameter \"Ptrans\" must be a matrix")
  }

  ifelse(rowSums(Ptrans) == 1, "", stop("The matrix \"Ptrans\" must be stochastic"))

  if ( sum(mu) != 1 ){
    stop("The vector \"init\" must be equal to 1")
  }

  if(!is.list(seq)){
    stop("The parameter \"seq\" should be a list")
  }
  ## Kpar: number of parameters of the model
  Kpar = (S-1)*S^k

  ## Computation of the log-likelihood for all sequences
  res = LoglikelihoodMk(seq = seq, E = E, mu = mu, Ptrans = Ptrans, k = k)
  LV = res$L
  nbSeq = length(seq)

  BIC.list = list()
  for (k in 1:nbSeq) {
    n = length(seq[[k]])
    BIC.list[[k]] = -2*LV[[k]] + log(n)*Kpar 
  } 


  return(BIC = BIC.list)
}

Try the SMM package in your browser

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

SMM documentation built on Jan. 31, 2020, 5:07 p.m.