R/computeL.R

#' computeL
#'
#' \code{computeL} calculates \bold{L_k(t)},
#' where \bold{L_k(t) = P( Z[t]=k | x[1:n])}
#'
#' @export
#' @param la   a matrix from forward algorithm
#' @param lb   a matrix from backward algorithm
#' @return     A matrix, \bold{L}.
#'
#' @examples
#' df <- uORF[[1]]
#' x=df$x; RNA=df$RNA; trans=df$trans; a=df$v; b=df$v/df$m; E=df$E
#'
#' la <- forwardAlg(x, RNA, trans, a, b, E)
#' lb <- backwardAlg(x, RNA, trans, a, b, E)
#' L <- computeL(la, lb)
#' table(df$z)       # check the first few entries of L against df$z
#' View(L)           # note 1st column and number of 1 in df$z
#'
#' rowSums(L)        # should all be 1

computeL <- function(la, lb){
  n <- dim(la)[1]
  la_n <- la[n,]
  L <- exp(la + lb - logSumExp(la_n))
  return(L)
}
shimlab/riboHMM2 documentation built on May 19, 2019, 6:23 p.m.