R/posterior_interval.R

Defines functions posterior_interval.blrm_trial posterior_interval.blrmfit

Documented in posterior_interval.blrmfit

#' Posterior intervals
#'
#' Posterior intervals of all model parameters.
#'
#' @param object fitted model object
#' @template args-prob
#' @template args-dots-ignored
#'
#' @details
#'
#' Reports the quantiles of posterior parameters which correspond to
#' the central probability mass specified. The output includes the
#' posterior of the hyper-parameters and the posterior of each group
#' estimate.
#'
#' @return Matrix of two columns for the central probability interval
#'     \code{prob} for all parameters of the model.
#'
#' @template start-example
#' @examples
#' example_model("single_agent", silent=TRUE)
#'
#' posterior_interval(blrmfit)
#'
#' @template stop-example
#' @method posterior_interval blrmfit
#' @aliases posterior_interval
#' @export
posterior_interval.blrmfit <- function(object, prob=0.95, ...) {
    pars <- c("mu_log_beta", "tau_log_beta", "rho_log_beta",  "beta_group")
    if(object$has_inter)
        pars <- c(pars, c("mu_eta", "tau_eta", "Sigma_corr_eta", "eta_group"))
    post <- as.matrix(object$stanfit, pars=pars)
    rstantools::posterior_interval(post, prob=prob)
}

#' @method posterior_interval blrm_trial
#' @export
posterior_interval.blrm_trial <- function(object, prob=0.95, ...) {
    .assert_is_blrm_trial_and_prior_is_set(object)
    return(posterior_interval.blrmfit(object$blrmfit, prob=prob, ...))
}

Try the OncoBayes2 package in your browser

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

OncoBayes2 documentation built on July 26, 2023, 5:30 p.m.