R/get_log_prior_d.R

Defines functions get_log_prior_d

get_log_prior_d <- function(parms, parm_names, priors) {
  # Calculate rowsums(log(prior density)) for non-uniform distributions (Fixed parameters should not be passed to function)
  log_prior_d <- Reduce(`+`, lapply(parm_names, FUN = function(x, dt, priors) {
    # Uniform adds no distance
    if (attr(priors, "distributions")[x] == "unif") {
      calc <- rep(0L, nrow(dt))
    } else {
      calc <- log(
        priors[[x]]$density_function(unlist(dt[, x, with = FALSE]))
      )
    }

    return(calc)
  }, dt = parms, priors = priors))

  return(log_prior_d)
}

Try the imabc package in your browser

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

imabc documentation built on April 12, 2021, 9:06 a.m.