binom_param: Generate Valid Binomial Parameters

binom_paramR Documentation

Generate Valid Binomial Parameters

Description

Creates a data frame of possible combinations of n (number of trials) and p (probabilities) that satisfy specified constraints on the mean, standard deviation, and approximation conditions for normal or Poisson distributions.

The function applies the following rules:

  • If length(mean) == 1 and it is an integer, it specifies the number of digits to which the mean should be rounded.

  • If mean = NA (default), all mean values are allowed.

  • If length(mean) > 1, only combinations where n * p equals one of the specified means are retained.

  • The same logic applies to sd for the standard deviation.

The norm and pois arguments can be logical, NA, or a custom function of the form ⁠function(n, p)⁠. They control which ⁠(n, p)⁠ pairs are considered valid:

  • NA allows all combinations.

  • A function returns TRUE for valid combinations and FALSE for invalid ones.

  • TRUE enforces standard approximation rules:

    • norm: n * p * (1 - p) > 9 (normal approximation condition)

    • pois: n > 10 & p < 0.05 (Poisson approximation condition)

  • FALSE excludes combinations that meet the approximation condition.

Note: The resulting data frame may be empty if no combinations meet all criteria.

Usage

binom_param(n, p, mean = NA, sd = NA, norm = NA, pois = NA, tol = 1e-06)

Arguments

n

integer vector of trial counts

p

numeric vector of probabilities

mean

numeric or integer specifying required mean digits or specific mean values

sd

numeric or integer specifying required standard deviation digits or specific sd values

norm

logical, NA, or function: restricts combinations to those valid for normal approximation

pois

logical, NA, or function: restricts combinations to those valid for Poisson approximation

tol

numeric: tolerance for numerical comparisons (default: 1e-6)

Value

A data frame with columns n, p, mean, and sd representing valid parameter combinations.

Examples

binom_param(1000:50000, (5:25)/100, mean = 0, sd = 0)

exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.