R/pull_prior.R

Defines functions pull_prior

Documented in pull_prior

#' pull_prior
#'
#' Extracts the priors from an object of class
#' \code{\link{bayesnecfit}} or \code{\link{bayesmanecfit}}.
#'
#' @param object An object of class \code{\link{bayesnecfit}}
#' or \code{\link{bayesmanecfit}} returned by \code{\link{bnec}}.
#' @return A \code{\link[base]{list}} containing the priors.
#'
#' @examples
#' library(bayesnec)
#' data(manec_example)
#' pull_prior(manec_example)
#'
#' @export
pull_prior <- function(object) {
  if (inherits(object, "bayesmanecfit")) {
    mods <- object$mod_fits
    out <- list()
    for (i in seq_along(mods)) {
      out[[i]] <- mods[[i]]$fit$prior
      names(out)[i] <- mods[[i]]$model
    }
    out
  } else if (inherits(object, "bayesnecfit")) {
    list(object$fit$prior)
  } else {
    stop("Object is not of class bayesnecfit or bayesmanecfit")
  }
}

Try the bayesnec package in your browser

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

bayesnec documentation built on Sept. 26, 2023, 9:06 a.m.