R/mixing_distribution_prior_draw.R

Defines functions PriorDraw.hierarchical PriorDraw

Documented in PriorDraw

#' Draw from the prior distribution
#'
#' @param mdObj Mixing Distribution
#' @param n Number of draws.
#' @return A sample from the prior distribution

#' @export
PriorDraw <- function(mdObj, n) UseMethod("PriorDraw", mdObj)

#' @export
PriorDraw.hierarchical <- function(mdObj, n = 1) {

  probs <- mdObj$pi_k

  ind <- sample(which(probs > 0), n, prob = probs[probs > 0], replace=TRUE)

  return(lapply(mdObj$theta_k, function(x) x[, , ind, drop = FALSE]))
}

Try the dirichletprocess package in your browser

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

dirichletprocess documentation built on Aug. 25, 2023, 5:19 p.m.