R/batestestR.R

#' Extract Bayes Factors from fitted models
#'
#' @description A wrapper around \code{\link[bayestestR]{bayesfactor_models}}
#'
#' @author Mattan S. Ben-Shachar
#'
#' @param ... fitted models (should all have been fitted on the same data)
#' @param .den which model should all models be compared to?
#' @param object object of type \code{BFBayesFactor}
#'
#' @details These functions return a simple \code{data.frame} of class \code{BFGrid} that print nicely
#' that can be passed to \code{inclusionBF}
#'
#' @return a data frame containing the logBFs of the supplied models, that prints nicely.
#'
#'
#' @export
BIC_BFs <- function(..., .den = 1){
  message("Using 'bayestestR::bayesfactor_models'")
  bayestestR::bayesfactor_models(..., denominator = .den)
}

#' @describeIn BIC_BFs Extract Bayes Factors from \code{brms} or \code{rstanarm} models
#' @export
stan_BFs <- BIC_BFs

#' @describeIn BIC_BFs Extract Bayes Factors from \code{BFBayesFactor}
#' @export
BayesFactor_BFs <- BIC_BFs

#' Get inclusion BFs for effects in a Bayesian model
#'
#' A wrapper around \code{\link[bayestestR]{bayesfactor_inclusion}}
#'
#' @author Mattan S. Ben-Shachar
#' @param BF an object of class \code{BFGrid}.
#' @param match_models If \code{FALSE} (default), Inclustion BFs are computed by
#' comparing all models with an effect against all models without the effect. If \code{TRUE},
#' Inclusion BFs are computed by comparing all models with an effect against models without
#' the effect AND without any higher-order interactions with the effect.
#' @param priorOdds optional vector of prior odds for the models (not including H0/H0). See \code{priorOdds} in \code{BayesFactor}
#'
#'
#' @return a data frame containing the prior and posterior probabilities, and BF for each effect.
#'
#' @export
inclusionBF <- function(BFGrid, match_models = FALSE, priorOdds = NULL){
  message("Using 'bayestestR::bayesfactor_inclusion'")
  bayestestR::bayesfactor_inclusion(BFGrid, match_models = match_models, prior_odds = priorOdds)
}
mattansb/BFEffect documentation built on June 7, 2019, 8:49 p.m.