Learn R Programming

randomizr (version 2.0.1)

obtain_num_permutations: Obtain the Number of Possible Permutations from a Random Assignment Declaration

Description

Counts the assignments a design could have produced. The count is the size of the randomization distribution, so it says how much resolution a randomization inference p-value can have: a design with 70 possible assignments cannot produce a p-value below 1/70. Counting is exact and cheap even when the number is far too large to enumerate, which is why it is worth calling before obtain_permutation_matrix().

Usage

obtain_num_permutations(declaration)

Value

A single number: how many distinct assignments (or samples) the declared design can produce. It can be far larger than any matrix you would want to build, which is the point of counting first.

Arguments

declaration

A random assignment or sampling declaration, created by declare_ra() or declare_rs(). (required)

See Also

obtain_permutation_matrix(), obtain_permutation_probabilities(), declare_ra()

Examples

Run this code

# Random assignment
## complete

declaration <- declare_ra(N = 4)
perms <- obtain_permutation_matrix(declaration)
dim(perms)
obtain_num_permutations(declaration)

## blocked

blocks <- c("A", "A", "B", "B", "C", "C", "C")
declaration <- declare_ra(blocks = blocks)
perms <- obtain_permutation_matrix(declaration)
dim(perms)
obtain_num_permutations(declaration)

## clustered

clusters <- c("A", "B", "A", "B", "C", "C", "C")
declaration <- declare_ra(clusters = clusters)
perms <- obtain_permutation_matrix(declaration)
dim(perms)
obtain_num_permutations(declaration)

## large

declaration <- declare_ra(20)
choose(20, 10)
perms <- obtain_permutation_matrix(declaration)
dim(perms)

# Random sampling
## complete

declaration <- declare_rs(N = 4)
perms <- obtain_permutation_matrix(declaration)
dim(perms)
obtain_num_permutations(declaration)

## stratified

strata <- c("A", "A", "B", "B", "C", "C", "C")
declaration <- declare_rs(strata = strata)
perms <- obtain_permutation_matrix(declaration)
dim(perms)
obtain_num_permutations(declaration)

## clustered

clusters <- c("A", "B", "A", "B", "C", "C", "C")
declaration <- declare_rs(clusters = clusters)
perms <- obtain_permutation_matrix(declaration)
dim(perms)
obtain_num_permutations(declaration)

## large

declaration <- declare_rs(N = 20)
perms <- obtain_permutation_matrix(declaration)
dim(perms)


Run the code above in your browser using DataLab