Learn R Programming

powerprior (version 1.0.0)

bayes_factor: Calculate Bayes Factor

Description

Computes the Bayes factor comparing two models with different discounting parameters.

Usage

bayes_factor(
  historical_data,
  current_data,
  a0_1,
  a0_2 = 0,
  multivariate = FALSE,
  ...
)

Value

Bayes factor (BF_12 = P(data|a0_1) / P(data|a0_2))

Arguments

historical_data

Historical data

current_data

Current data

a0_1

First discounting parameter

a0_2

Second discounting parameter (default: 0)

multivariate

Logical indicating multivariate data (default: FALSE)

...

Additional arguments passed to powerprior functions

Details

The Bayes factor compares the marginal likelihoods under two different discounting parameters. BF > 1 favors a0_1, BF < 1 favors a0_2.

Note: This is a simple approximation using the observed data likelihood evaluated at posterior means.

Examples

Run this code
set.seed(123)
historical <- rnorm(50, mean = 10, sd = 2)
current <- rnorm(30, mean = 10.5, sd = 2)

# Compare moderate borrowing (0.5) vs no borrowing (0)
bf <- bayes_factor(historical, current, a0_1 = 0.5, a0_2 = 0)
cat("Bayes Factor:", bf, "\n")

Run the code above in your browser using DataLab