R/likelihoods.R

Defines functions calc.log.lkl.allfiles calc.log.lkl.tailfiles calc.log.lkl.lastfile

# Calculate the log likelihood of comparisons only involving the last file
# Parameters:
#   lastfilecmps = list of k-1 comparison data objects, comparing each of the first
#     k-1 files with the kth file. This is the last element in the triangular
#     list-of-lists format for all comparison data.
#   m,u = current parameter values
#   sl = streaminglinks object defining current link state
# Returns:
#   a single number, the log likelihood of Gamma^{(k)}, all comparisons
#   involving the most recent file k.
calc.log.lkl.lastfile <- function(lastfilecmps, m, u, sl) {
  # Calculate the disagreement level counts
  counts <- disag.counts.lastfile(lastfilecmps, sl)
  # The log likelihood is these counts combined with log m and log u
  return(sum(counts$match * log(m)) + sum(counts$nonmatch * log(u)))
}

calc.log.lkl.tailfiles <- function(cmpdata, m, u, sl, startfile) {
  # Calculate the disagreement level counts
  counts <- disag.counts.tailfiles(cmpdata, sl, startfile)
  # The log likelihood is these counts combined with log m and log u
  return(sum(counts$match * log(m)) + sum(counts$nonmatch * log(u)))
}

calc.log.lkl.allfiles <- function(cmpdata, m, u, sl) {
  # Calculate the disagreement level counts
  counts <- disag.counts.allfiles(cmpdata, sl)
  # The log likelihood is these counts combined with log m and log u
  return(sum(counts$match * log(m)) + sum(counts$nonmatch * log(u)))
}

Try the bstrl package in your browser

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

bstrl documentation built on Nov. 11, 2022, 1:06 a.m.