Skip to contents

This function calculates a posterior probability for hypotheses about population densities of the form \(H:\mu > \psi\) or \(H:\mu < \psi\), given the data at a single iteration. This function is to be used in a sequential framework, and called on the sequential test stbp_composite.

Usage

stbp_posterior_composite(
  data,
  greater_than,
  hypothesis,
  density_func,
  overdispersion = NA,
  prior,
  lower_bnd = 0,
  upper_bnd = Inf
)

Arguments

data

For count data, a numeric vector with for a single sampling bout (NAs allowed). For binomial data, a matrix with observations in col 1 and samples in col 2 (NAs not allowed).

greater_than

logical; if TRUE, the tested hypothesis is of the form \(H:\mu > \psi\) otherwise, \(H:\mu < \psi\).

hypothesis

Single non-negative value with the hypothesized value of \(\mu\).

density_func

Kernel probability density function for the data. See details.

overdispersion

A character string (if a function) or a number specifying the overdispersion parameter. Only required when using "negative binomial" or "beta-binomial" as kernel densities. See details.

prior

Single number with initial prior. Must be on the interval \([0,1]\).

lower_bnd

Single number indicating the lower bound of the parameter space for \(\mu\). Most cases is \(0\) (default).

upper_bnd

Single number indicating the upper bound of the parameter space for \(\mu\). For count data, is often Inf (default), but it must be \(\leq 1\) for binomial data.

Value

A single probability

Details

The density_func argument should be specified as character string. Acceptable options are "poisson", "negative binomial", "binomial" and "beta-binomial". The overdispersion parameter for "negative binomial" and "beta-binomial" can be either a constant or a function of the mean. If a function, it should be specified as a character string with the name of an existing function. For options of empirical functions to describe overdispersion as a function of the mean see Binns et al. (2000). The most common approach for the negative binomial family is Taylor's Power Law.

References

Binns, M.R., Nyrop, J.P. & Werf, W.v.d. (2000) Sampling and monitoring in crop protection: the theoretical basis for developing practical decision guides. CABI Pub., Wallingford, Oxon, UK; New York, N.Y.

Rincon, D.F., McCabe, I. & Crowder, D.W. (2025) Sequential testing of complementary hypotheses about population density. Methods in Ecology and Evolution. <https://doi.org/10.1111/2041-210X.70053>

Examples


# Counts collected in a single sampling bout
counts <- c(1, 2, 3)

# Calculate posterior probability from a naive 0.5 prior for H1:mu>2
# (a population being >2 individuals per sampling unit) with
# a poisson kernel

stbp_posterior_composite(data = counts,
                          greater_than = TRUE,
                          hypothesis = 2,
                          density_func = "poisson",
                          prior = 0.5,
                          lower_bnd = 0,
                          upper_bnd = Inf) # returns 0.60630278
#> [1] 0.6063028

# Same analysis but with a negative binomial kernel.
# Note that 'overdispersion' can either be a positive number or a function.

stbp_posterior_composite(data = counts,
                          greater_than = TRUE,
                          hypothesis = 2,
                          density_func = "negative binomial",
                          overdispersion = 2,
                          prior = 0.5,
                          lower_bnd = 0,
                          upper_bnd = Inf) # returns 0.72558593
#> [1] 0.7255859
## End (Not run)