Random sampling from a binomial posterior distribution, using weights
Source:R/rposterior.R
wbinpost.RdSamples from the posterior distribution of the probability \(p\) of a binomial distribution. User-supplied weights are applied to each observation when constructing the log-likelihood.
Arguments
- n
A numeric scalar. The size of posterior sample required.
- prior
A function to evaluate the prior, created by
set_bin_prior.prior$priormust be"bin_beta".- ds_bin
A numeric list. Sufficient statistics for inference about the binomial probability \(p\). Contains
sf: a logical vector of success (TRUE) and failure (FALSE) indicators.w: a numeric vector of lengthlength(sf)containing the values by which to multiply the observations when constructing the log-likelihood.
Value
An object (list) of class "binpost" with components
bin_sim_vals:An
nby 1 numeric matrix of values simulated from the posterior for the binomial probability \(p\)bin_logf:A function returning the log-posterior for \(p\).
bin_logf_args:A list of arguments to
bin_logf.
Details
For prior$prior == "bin_beta" the posterior for \(p\)
is a beta distribution so rbeta is used to
sample from the posterior.
See also
set_bin_prior for setting a prior distribution
for the binomial probability \(p\).
