R/likelihood.R

Defines functions likelihood

Documented in likelihood

#' @name likelihood
#'
#' @title Read and Set Likelihood to the Corresponding Conjugate Prior
#'
#' @description Read and set the likelihood distribution corresponding to the conjugate prior distribution.
#'
#' @param mix Prior mixture distribution.
#' @param value New likelihood. \strong{Should} only be changed for Gamma priors as these are supported
#' with either Poisson (\code{value="poisson"}) or Exponential (\code{value="exp"}) likelihoods.
#'
#' @details
#' If the prior and posterior distributions are in the same family, then the prior distribution
#' is called a conjugate prior for the likelihood function.
#'
#' @template conjugate_pairs
#'
#' @examples
#'
#' # Gamma mixture
#' gmix <- mixgamma(c(0.3, 20, 4), c(0.7, 50, 10))
#'
#' # read out conjugate partner
#' likelihood(gmix)
#'
#' ess(gmix)
#'
#' # set conjugate partner
#' likelihood(gmix) <- "exp"
#'
#' # ... which changes the interpretation of the mixture
#' ess(gmix)
NULL

#' @rdname likelihood
#' @export
likelihood <- function(mix) {
    likelihood <- attr(mix, "likelihood")
    check_choice(likelihood, c("poisson", "exp", "normal", "binomial"))
    likelihood
}

#' @rdname likelihood
#' @export
'likelihood<-' <- function(mix, value) {
    check_choice(value, c("poisson", "exp", "normal", "binomial"))
    attr(mix, "likelihood") <- value
    mix
}

Try the RBesT package in your browser

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

RBesT documentation built on Aug. 22, 2023, 1:08 a.m.