| allmultinom | R Documentation |
Generates the complete set of non-negative integer vectors
(x_{00}, x_{01}, x_{10}, x_{11}) satisfying
x_{00} + x_{01} + x_{10} + x_{11} = n_j, where n_j is the
sample size of group j \in \{t, c\}. Each row of the returned matrix
corresponds to one possible realisation of the aggregated bivariate binary
counts. This enumeration is a prerequisite for exact operating
characteristic assessment in pbayesdecisionprob2bin.
allmultinom(n)
n |
A single non-negative integer giving the sample size of the group
( |
The number of non-negative integer solutions to
x_{00} + x_{01} + x_{10} + x_{11} = n_j is the stars-and-bars count
\binom{n_j + 3}{3} = \frac{(n_j + 1)(n_j + 2)(n_j + 3)}{6}.
For example, n_j = 10 yields 286 rows and n_j = 20 yields
1771 rows. The matrix is pre-allocated to avoid repeated memory
reallocation, making the function efficient for the sample sizes typical
in rare-disease proof-of-concept studies.
This function is an internal computational building block used by
pbayesdecisionprob2bin to enumerate the sample space over
which multinomial probabilities and decision indicators are summed when
computing exact operating characteristics.
An integer matrix with \binom{n_j + 3}{3} rows and 4 columns
named x00, x01, x10, x11.
Each row is a distinct non-negative integer solution to
x_{00} + x_{01} + x_{10} + x_{11} = n_j.
Rows are ordered by x00 (ascending), then x10
(ascending), then x01 (ascending).
# Example 1: n = 2 (smallest non-trivial case)
allmultinom(2)
# Example 2: n = 10 (typical rare-disease PoC group size)
mat <- allmultinom(10)
nrow(mat) # Should be choose(13, 3) = 286
all(rowSums(mat) == 10) # Every row must sum to n
# Example 3: n = 0 (edge case - only the all-zero row)
allmultinom(0)
# Example 4: Verify column names
colnames(allmultinom(5))
# Example 5: Row counts match the stars-and-bars formula
n <- 15L
mat <- allmultinom(n)
nrow(mat) == choose(n + 3L, 3L) # Should be TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.