Calculate binomial probabilities for aligned structures

Description

Assess how often a specified number of independent structures would face a target by chance, given the chance for one structure.

Usage

bernoulli.trial(n, p, r, type = "tail")

Arguments

n

Total number of structures: a single finite nonnegative integer.

p

Target probability: a single finite number between 0 and 1.

r

Number of hits: a single finite integer between 0 and n.

type

Either "single" for exactly r hits or "tail" for at least r hits (the default).

Details

Define a hit and the per-structure chance of a hit before counting the orientations. A single-count probability answers how often exactly that count arises; the upper tail answers how often a count at least that large arises.

The binomial model assumes independent structures with the same target probability p. The upper-tail probability is a one-sided p-value under this model. Calculations use stats::dbinom and stats::pbinom, avoiding factorial overflow and subtraction from 1. At least zero hits has probability 1. With zero structures, zero hits has probability 1 for either type. Inputs are scalar; invalid inputs error.

Value

A numeric probability between 0 and 1.

Validation

Exact and upper-tail probabilities agreed with independent binomial calculations for the tested counts up to 1,000, including zero hits. See S03 validation in the technical manual.

Scientific checks

References

Ruggles, C (1999) Astronomy in Prehistoric Britain and Ireland. Yale University Press.

See Also

randomTest, modelTest

Examples

# At least 10 out of 30 structures, with targets covering 20% of the horizon:
bernoulli.trial(30, 0.2, 10)
# Exactly 10 hits:
bernoulli.trial(30, 0.2, 10, type="single")
bernoulli.trial(30, 0.2, 0) # Always 1
bernoulli.trial(1000, 0.2, 250) # No factorial overflow