wbinpost: Random sampling from a binomial posterior distribution, using...

View source: R/rposterior.R

wbinpostR Documentation

Random sampling from a binomial posterior distribution, using weights

Description

Samples 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.

Usage

wbinpost(n, prior, ds_bin)

Arguments

n

A numeric scalar. The size of posterior sample required.

prior

A function to evaluate the prior, created by set_bin_prior. prior$prior must 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 length length(sf) containing the values by which to multiply the observations when constructing the log-likelihood.

Details

For prior$prior == "bin_beta" the posterior for p is a beta distribution so rbeta is used to sample from the posterior.

Value

An object (list) of class "binpost" with components

bin_sim_vals:

An n by 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.

See Also

set_bin_prior for setting a prior distribution for the binomial probability p.

Examples

u <- quantile(gom, probs = 0.65)
ds_bin <- list(sf = gom > u, w = rep(1, length(gom)))
bp <- set_bin_prior(prior = "jeffreys")
temp <- wbinpost(n = 1000, prior = bp, ds_bin = ds_bin)
graphics::hist(temp$bin_sim_vals, prob = TRUE)

paulnorthrop/revdbayes documentation built on March 20, 2024, 1:01 a.m.