The bayesrules package has a set of functions that support exploring Bayesian models from three conjugate families: Beta-Binomial, Gamma-Poisson, and Normal-Normal. The functions either help with plotting (prior, likelihood, and/or posterior) or summarizing the descriptives (mean, mode, variance, and sd) of the prior and/or posterior.
We use the Beta-Binomial model to show the different set of functions and the arguments.
plot_beta(alpha = 3, beta = 13, mean = TRUE, mode = TRUE)
#> Warning in geom_segment(aes(x = mean, y = 0, xend = mean, yend = dbeta(mean, : All aesthetics have length 1, but the data has 2 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning in geom_segment(aes(x = mode, y = 0, xend = mode, yend = stats::dbeta(mode, : All aesthetics have length 1, but the data has 2 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
In addition, plot_binomial_likelihood()
helps users
visualize the Binomial likelihood function and shows the maximum
likelihood estimate.
The two other functions plot_beta_binomial()
and
summarize_beta_binomial()
require both the prior parameters
and the data for the likelihood.
For Gamma-Poisson and Normal-Normal models, the set of functions are
similar but the arguments are different for each model. Arguments of the
Gamma-Poisson functions include the shape
and
rate
of the Gamma prior and sum_y
and
n
arguments related to observed data which represent the
sum of observed data values and number of observations respectively.
plot_gamma_poisson(
shape = 3,
rate = 4,
sum_y = 3,
n = 9,
prior = TRUE,
likelihood = TRUE,
posterior = TRUE
)
For the Normal-Normal model functions, the prior Normal model has the
mean
and sd
argument. The observed data has
sigma
, y_bar
, and n
which
indicate the standard deviation, mean, and sample size of the data
respectively.