savage_dickey: Calculate Bayes Factor using Savage-Dickey density ratio.

Description Usage Arguments Details Value Author(s) Examples

View source: R/savage_dickey.R

Description

Creates plot of prior and posterior distributions and calculates the Bayes factor at the point of interest (Q).

Usage

1
2
3
4
5
6
7
8
9
savage_dickey(
  post,
  prior,
  Q,
  xlab = "Parameter values",
  ylab = "Density",
  plot = TRUE,
  print_plot = FALSE
)

Arguments

post

Samples from posterior distribution (Numeric)

prior

Samples from prior distribution (Numeric)

Q

Point on x-axis for calculating Bayes factor.

xlab

Label for x-axis

ylab

Label for y-axis

plot

Create density plot (Logical)

print_plot

(Logical)

Details

Bayes factors are calculated using the polspline package.

BF10 <- dlogspline(Q, logspline(post)) / dlogspline(Q,logspline(prior))

BF01 <- dlogspline(Q, logspline(prior)) / dlogspline(Q,logspline(post))

Value

List with ggplot2 object (optional), BF10 and BF01, Maximum a posteriori and priori at point Q

Author(s)

Benjamin Hugh Zachariae

Ludvig Renbo Olsen

Examples

1
2
3
4
5
6
# Sampling from two different gaussian distributions
prior <- rnorm(1000, mean=0, sd=1)
posterior <- rnorm(1000, mean=2, sd=2)

# Calculating BF and generating plot of the given distributions
s_d <- savage_dickey(posterior, prior, Q = 0, plot = TRUE)

LudvigOlsen/LRO.utilities documentation built on Nov. 13, 2020, 11:26 a.m.