| Title: | Feasible Sample Sizes from Incomplete Design Information |
|---|---|
| Description: | Identifies feasible sample sizes under specified false negative and false positive requirements when planning information leaves several compatible distributions. Computes inner and outer set bounds, evaluates normal and paired binary designs, and compares prespecified rules with a finite decision class. For multivariate binary distributions with fixed proper subset margins, rational arithmetic and Sturm sequences give exact feasibility calculations over the full compatibility interval. Implements the framework of Nakamura (2026) <doi:10.3390/stats9050105>. |
| Authors: | Satoshi Nakamura [aut, cre, cph] |
| Maintainer: | Satoshi Nakamura <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-23 16:55:48 UTC |
| Source: | https://github.com/cran/feasiblesize |
Calculates feasible sets for prespecified rules under false negative and false positive requirements. Compatible states yield inner and outer set bounds. Exact binary calculations use rational arithmetic over the complete affine compatibility interval. Normal and conditional paired binary operating probabilities use numerical distribution functions.
Maintainer: Satoshi Nakamura [email protected] [copyright holder]
Authors:
Satoshi Nakamura [email protected] [copyright holder]
Nakamura, S. (2026). Identifying Feasible Sample Sizes from Incomplete Design Information. Stats, 9(5), 105. doi:10.3390/stats9050105.
size_bounds(), normal_size_bounds(),
coordinate_feasibility(), classify_rule_family().
Binary Cells in Lexicographic Order
binary_cells(dimension)binary_cells(dimension)
dimension |
Number of binary variables, an integer from 2 to 20. |
Integer matrix, one cell per row; the last coordinate varies fastest.
binary_cells(2)binary_cells(2)
Exact Compatibility Interval for Fixed Proper Subset Margins
binary_compatibility(baseline)binary_compatibility(baseline)
baseline |
A compatible baseline distribution from |
All proper subset margins must be treated as fixed planning inputs.
Every compatible mass is p0(y) + lambda * product(2*y[j]-1).
The supplied baseline must already be compatible; this function does not
solve for a baseline from arbitrary margins. It does not replace sampling
uncertainty in estimated margins with an exact population guarantee.
An fs_compatibility object with exact lower, upper, eta_baseline,
eta_lower, eta_upper, endpoint zero cells, and the baseline distribution.
binary_compatibility(binary_mass(rep("1/8", 8)))binary_compatibility(binary_mass(rep("1/8", 8)))
An Exact Multivariate Binary Distribution
binary_mass(probabilities, dimension = log2(length(probabilities)))binary_mass(probabilities, dimension = log2(length(probabilities)))
probabilities |
Complete cell probabilities in the order of
|
dimension |
Number of binary coordinates; inferred from the vector length if omitted. |
An fs_binary_mass object with cells and exact probabilities.
binary_mass(rep("1/4", 4))binary_mass(rep("1/4", 4))
Classify a Finite Family of Rules over the Full State Interval
classify_rule_family(compatibility, n, planned_rule, rule_family)classify_rule_family(compatibility, n, planned_rule, rule_family)
compatibility |
Binary compatibility interval. |
n |
Candidate sample sizes. |
planned_rule |
Name of the prespecified rule. |
rule_family |
Named list of rules. Each rule is a named list indexed by character sample sizes, each containing its polynomial risk constraints. |
T1: the planned rule works everywhere. T2: one common alternative works everywhere. T3: some rule works at each state, but no one rule works everywhere. T4: a rule works at some states only. T5: no rule works anywhere. Common roots from all rules are used to preserve the quantifier order. The planned rule outer bound differs from the decision class outer bound.
A list with four nested sets, five cases T1 through T5, prespecified
rule inner and outer bounds, and candidate specific evidence.
cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) ok <- list(risk_constraint("fp", "false_positive", 0L, "1/2")) classify_rule_family(cpt, 1L, "planned", list(planned = list("1" = ok)))cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) ok <- list(risk_constraint("fp", "false_positive", 0L, "1/2")) classify_rule_family(cpt, 1L, "planned", list(planned = list("1" = ok)))
Evaluate a Compatible Binary Distribution
compatible_distribution(compatibility, coordinate)compatible_distribution(compatibility, coordinate)
compatibility |
An object from |
coordinate |
One exact lambda coordinate in the closed interval. |
An exact binary mass.
cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) compatible_distribution(cpt, "1/8")cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) compatible_distribution(cpt, "1/8")
Exact Feasibility over a Binary Compatibility Interval
coordinate_feasibility(compatibility, constraints, refinement_steps = 24L)coordinate_feasibility(compatibility, constraints, refinement_steps = 24L)
compatibility |
Object from |
constraints |
Nonempty list of uniquely named |
refinement_steps |
Positive number of exact root bisections. |
Certifies the entire closed interval, including isolated feasible
points, using exact rational arithmetic and Sturm root isolation. The
classification is "feasible_everywhere", "unidentified", or
"infeasible_everywhere". A finite collection of constraint polynomials
must correctly represent the supplied statistical problem; their
statistical derivation is the caller's responsibility.
An fs_coordinate_result with classification, all boundary points,
signs, rational witnesses between boundaries, and feasible components.
Components contain one based boundary indices lower and upper.
cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) p <- rational_polynomial(c("1/2", 2L)) coordinate_feasibility(cpt, list( risk_constraint("fn", "false_negative", 1L-p, "3/4"), risk_constraint("fp", "false_positive", p, "3/4")))cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) p <- rational_polynomial(c("1/2", 2L)) coordinate_feasibility(cpt, list( risk_constraint("fn", "false_negative", 1L-p, "3/4"), risk_constraint("fp", "false_positive", p, "3/4")))
Directional Evidence Relative to a Feasible Comparator
directional_evidence(n, risks, beta = 0.2, gamma = 0.2)directional_evidence(n, risks, beta = 0.2, gamma = 0.2)
n |
One candidate size. |
risks |
Risk table as in |
beta, gamma
|
Error tolerances. |
A failed constraint alone does not justify a directional claim. A smaller feasible comparator is required for "too large", and a larger feasible comparator for "too small", under the same rule and state.
A list with a status and feasible smaller or larger comparators.
directional_evidence(1000, normal_risks(1:1000))directional_evidence(1000, normal_risks(1:1000))
Exact Rational Inputs
exact_rational(x)exact_rational(x)
x |
An integer, rational or decimal character vector, or a |
Use character input such as "0.1" or "1/10" to state an exact
probability. Binary floating point inputs such as 0.1 are not silently
treated as exact decimal probabilities. Integer doubles up to 2^53 are accepted.
A bigq vector of exact rational numbers.
exact_rational(c("0.1", "1/3", "1e-3"))exact_rational(c("0.1", "1/3", "1e-3"))
Feasible Sizes under Two Error Requirements
feasible_sizes(risks, beta = 0.2, gamma = 0.2)feasible_sizes(risks, beta = 0.2, gamma = 0.2)
risks |
Data frame with columns |
beta |
Maximum probability of missing a meaningful effect. |
gamma |
Maximum probability of a positive decision for a negligible effect. |
Both inequalities are inclusive. The calculation is conditional on the supplied risks; it does not validate their statistical derivation.
Sorted integer vector of feasible candidate sizes.
feasible_sizes(normal_risks(1:100))feasible_sizes(normal_risks(1:100))
Operating Probabilities for a Normal Mean
normal_risks( n, d_negligible = 0.1, d_meaningful = 0.5, sigma = 1, alpha = 0.05, rule = c("point", "minimum"), calibration_sigma = sigma )normal_risks( n, d_negligible = 0.1, d_meaningful = 0.5, sigma = 1, alpha = 0.05, rule = c("point", "minimum"), calibration_sigma = sigma )
n |
Distinct positive candidate sizes. |
d_negligible |
Upper boundary of negligible effects. |
d_meaningful |
Lower boundary of meaningful effects; must exceed
|
sigma |
Positive standard deviation of one observation. |
alpha |
One sided nominal significance level. |
rule |
|
calibration_sigma |
Positive, fixed standard deviation used to set the
critical value. Defaults to |
Assumes independent normal observations. Rejects when the sample
mean exceeds null_boundary + qnorm(1-alpha)*calibration_sigma/sqrt(n).
Risks are evaluated at the declared effect boundaries. Floating point
normal probabilities are used, rather than exact arithmetic.
A data frame of candidate sizes, both risks, and power.
feasible_sizes(normal_risks(1:1000)) feasible_sizes(normal_risks(1:1000, rule = "minimum"))feasible_sizes(normal_risks(1:1000)) feasible_sizes(normal_risks(1:1000, rule = "minimum"))
Normal Bounds over a Continuous Standard Deviation Interval
normal_size_bounds( n, sigma_range, d_negligible = 0.1, d_meaningful = 0.5, alpha = 0.05, rule = c("point", "minimum"), beta = 0.2, gamma = 0.2, calibration_sigma = max(sigma_range) )normal_size_bounds( n, sigma_range, d_negligible = 0.1, d_meaningful = 0.5, alpha = 0.05, rule = c("point", "minimum"), beta = 0.2, gamma = 0.2, calibration_sigma = max(sigma_range) )
n |
Distinct positive candidate sizes. |
sigma_range |
Two ordered positive standard deviation endpoints. |
d_negligible |
Upper boundary of negligible effects. |
d_meaningful |
Lower boundary of meaningful effects; must exceed
|
alpha |
One sided nominal significance level. |
rule |
|
beta, gamma
|
Error tolerances, each strictly between zero and one half. |
calibration_sigma |
Positive, fixed standard deviation used to set the
critical value. Defaults to |
Uses one common critical value calibrated with calibration_sigma,
which defaults to the upper endpoint. When both error tolerances are below
one half, a feasible critical mean must lie between the effect boundaries.
Both risks then increase with sigma, so endpoint calculations give the
exact inner and outer sets for this normal model. If sigma were known
separately in each state and the critical value changed with it, that
would be a different family of rules.
An fs_size_bounds object over the complete closed sigma_range.
b <- normal_size_bounds(1:800, sigma_range = c(0.22, 0.30), d_negligible = 0.02, d_meaningful = 0.05, rule = "minimum") min(b$inner)b <- normal_size_bounds(1:800, sigma_range = c(0.22, 0.30), d_negligible = 0.02, d_meaningful = 0.05, rule = "minimum") min(b$inner)
Exact Operating Probability Polynomial for a Fixed Rule
operating_polynomial(compatibility, n, rule, max_sequences = 1000000L)operating_polynomial(compatibility, n, rule, max_sequences = 1000000L)
compatibility |
Binary compatibility interval. |
n |
A positive integer sample size. |
rule |
Function taking an integer matrix with n rows and returning an
exact conditional positive decision probability in |
max_sequences |
Maximum ordered samples to enumerate; positive integer. |
Enumeration is exponential. This constructor is intended for small
exact examples. For larger designs supply analytically derived risk
polynomials to risk_constraint() or use a supported model calculation.
The rule is fixed across lambda; it must not access the unknown coordinate.
Exact rational polynomial in lambda.
cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) operating_polynomial(cpt, 1L, function(s) as.integer(prod(2*s[1,]-1) == 1))cpt <- binary_compatibility(binary_mass(rep("1/4", 4))) operating_polynomial(cpt, 1L, function(s) as.integer(prod(2*s[1,]-1) == 1))
Operating Probabilities for Independent Paired Binary Observations
paired_binary_risks( n, discordance, d_negligible = 0.01, d_meaningful = 0.05, alpha = 0.05, rule = c("point", "minimum"), calibration_discordance = NULL )paired_binary_risks( n, discordance, d_negligible = 0.01, d_meaningful = 0.05, alpha = 0.05, rule = c("point", "minimum"), calibration_discordance = NULL )
n |
Distinct positive candidate sizes. |
discordance |
Probability that the paired outcomes disagree, in (0,1]. |
d_negligible, d_meaningful
|
Boundaries for the difference P(1,0)-P(0,1). |
alpha |
One sided nominal level. |
rule |
|
calibration_discordance |
Discordance used to calibrate the minimum effect rule. Must be supplied explicitly for that rule. Hold it fixed across states if the actual discordance is uncertain. |
Conditions on the discordant count M, which is Binomial(n,r).
Given M, positive discordances are Binomial(M,(r+d)/(2*r)). Uses the strict
critical count qbinom(1-alpha,M,p0)+1. Summing the exact binomial model
probabilities over M removes Monte Carlo error, but the numerical
probabilities use floating point arithmetic. Summation roundoff within
1e-12 of [0,1] is clipped to that interval; larger violations are errors.
The zero boundary critical
counts do not depend on r. A minimum effect rule calibrated separately
with each unknown state is not a common implementable rule. This function
therefore requires its calibration discordance to be explicit.
Data frame with both error probabilities and power.
paired_binary_risks(c(300, 500, 1000), 0.11275) paired_binary_risks(c(500, 1000), 0.11275, rule = "minimum", calibration_discordance = 0.11275)paired_binary_risks(c(300, 500, 1000), 0.11275) paired_binary_risks(c(500, 1000), 0.11275, rule = "minimum", calibration_discordance = 0.11275)
Discordance Bounds from Paired Binary Margins
paired_discordance_bounds(p_first, p_second, minimum_difference = 0)paired_discordance_bounds(p_first, p_second, minimum_difference = 0)
p_first, p_second
|
Marginal success probabilities. |
minimum_difference |
Optional nonnegative boundary that the discordance must permit, for example the meaningful difference. |
Named vector with the sharp lower and upper discordance bounds,
restricted by minimum_difference. Errors if the restricted set is empty.
paired_discordance_bounds(0.4, 0.35, 0.05)paired_discordance_bounds(0.4, 0.35, 0.05)
Plot Inner and Outer Sample Size Bounds
## S3 method for class 'fs_size_bounds' plot(x, y = NULL, ...)## S3 method for class 'fs_size_bounds' plot(x, y = NULL, ...)
x |
An object returned by |
y |
Unused. |
... |
Additional graphical arguments passed to |
x, invisibly. Produces a plot.
Evaluate an Exact Polynomial
polynomial_evaluate(polynomial, x)polynomial_evaluate(polynomial, x)
polynomial |
An object from |
x |
One exact rational coordinate. |
One exact bigq rational.
polynomial_evaluate(rational_polynomial(c("1/2", 1L)), "1/4")polynomial_evaluate(rational_polynomial(c("1/2", 1L)), "1/4")
Isolate Real Roots Using Exact Sturm Sequences
polynomial_roots(polynomial, lower, upper, refinement_steps = 24L)polynomial_roots(polynomial, lower, upper, refinement_steps = 24L)
polynomial |
An exact rational polynomial. |
lower, upper
|
Exact endpoints of a closed interval. |
refinement_steps |
Positive integer number of bisections once an interval contains exactly one root. This controls the displayed isolating width, not the validity of the root count. |
Repeated roots are counted once. Identically zero polynomials are rejected. No finite grid or floating point root finder is used.
Ordered list of roots, each represented by exact rational lower
and upper. Equal bounds denote an exact rational root. Unequal bounds
are an open isolating interval containing exactly one distinct root.
polynomial_roots(rational_polynomial(c(-2L, 0L, 1L)), 0L, 2L)polynomial_roots(rational_polynomial(c(-2L, 0L, 1L)), 0L, 2L)
Proper Subset Margins of an Exact Binary Mass
proper_subset_margins(mass)proper_subset_margins(mass)
mass |
An object from |
A list of exact marginal tables for every proper coordinate subset, including the empty subset. Coordinates in names use R's one based indexing.
proper_subset_margins(binary_mass(rep("1/4", 4)))proper_subset_margins(binary_mass(rep("1/4", 4)))
Rational Polynomials in Ascending Coefficient Order
rational_polynomial(coefficients = 0L)rational_polynomial(coefficients = 0L)
coefficients |
Exact inputs, in ascending powers of the variable. |
Integer and character constants can be used directly in polynomial
arithmetic. Wrap a bigq constant in rational_polynomial() before mixed
arithmetic to avoid conflicting S3 arithmetic methods from package 'gmp'.
An fs_polynomial object. Arithmetic +, -, *, and nonnegative
integer powers preserve exact rational coefficients.
x <- rational_polynomial(c(0L, 1L)) p <- (x - "1/3")^2 polynomial_evaluate(p, "1/3")x <- rational_polynomial(c(0L, 1L)) p <- (x - "1/3")^2 polynomial_evaluate(p, "1/3")
A Polynomial Error Constraint
risk_constraint(name, kind, polynomial, upper_bound)risk_constraint(name, kind, polynomial, upper_bound)
name |
Unique, nonempty name. |
kind |
One of |
polynomial |
Exact risk polynomial in lambda. |
upper_bound |
Exact tolerance in |
Risk polynomials are verified to stay in [0,1] over the complete
interval by coordinate_feasibility(). Generic "other" constraints
omit this range requirement.
An fs_constraint object representing polynomial <= upper_bound.
risk_constraint("fp", "false_positive", rational_polynomial(c("1/2", 1L)), "1/2")risk_constraint("fp", "false_positive", rational_polynomial(c("1/2", 1L)), "1/2")
Inner and Outer Bounds over a Finite State Set
size_bounds(risks, beta = 0.2, gamma = 0.2)size_bounds(risks, beta = 0.2, gamma = 0.2)
risks |
Data frame with |
beta, gamma
|
Error tolerances as in |
The inner bound is the intersection and the outer bound the union
of the state specific feasible sets. A finite sample of nuisance values
does not certify bounds over a continuous identified set. Use
coordinate_feasibility() for the supported exact polynomial calculation.
An object of class fs_size_bounds with inner, outer,
unidentified, infeasible, by_state, and the complete risk table.
r <- rbind(transform(normal_risks(1:100), state = "a"), transform(normal_risks(1:100, sigma = 1.2), state = "b")) size_bounds(r)r <- rbind(transform(normal_risks(1:100), state = "a"), transform(normal_risks(1:100, sigma = 1.2), state = "b")) size_bounds(r)