# binpost: Random sampling from a binomial posterior distribution In revdbayes: Ratio-of-Uniforms Sampling for Bayesian Extreme Value Analysis

## 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

• `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`.

`set_bin_prior` for setting a prior distribution for the binomial probability p.
 ```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) ```