binpost: Random sampling from a binomial posterior distribution

Description Usage Arguments Details Value See Also Examples

View source: R/rposterior.R

Description

Samples from the posterior distribution of the probability p of a binomial distribution.

Usage

1
binpost(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.

ds_bin

A numeric list. Sufficient statistics for inference about a binomial probability p. Contains

  • n_raw : number of raw observations

  • m : number of threshold exceedances.

Details

If prior$prior == "bin_beta" then the posterior for p is a beta distribution so rbeta is used to sample from the posterior. If prior$prior == "bin_mdi" then rejection sampling is used to sample from the posterior with an envelope function equal to the density of a beta(ds$m + 1, ds$n_raw - ds$m + 1) density.

Value

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

See Also

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

Examples

1
2
3
4
5
6
7
8
data(gom)
u <- quantile(gom, probs = 0.65)
ds_bin <- list()
ds_bin$n_raw <- length(gom)
ds_bin$m <- sum(gom > u)
bp <- set_bin_prior(prior = "jeffreys")
temp <- binpost(n = 1000, prior = bp, ds_bin = ds_bin)
graphics::hist(temp$bin_sim_vals, prob = TRUE)

revdbayes documentation built on Feb. 13, 2018, 1:04 a.m.