Declare a random assignment procedure.

declare_ra(N = NULL, blocks = block_var, clusters = clust_var, m = NULL,
m_each = NULL, prob = NULL, prob_each = NULL, block_m = NULL,
block_m_each = NULL, block_prob = NULL, block_prob_each = NULL,
num_arms = NULL, conditions = condition_names, simple = FALSE,
permutation_matrix = NULL, check_inputs = TRUE, block_var = NULL,
clust_var = NULL, condition_names = NULL)

Value

A list of class "declaration". The list has five entries: $ra_function, a function that generates random assignments according to the declaration.$ra_type, a string indicating the type of random assignment used $probabilities_matrix, a matrix with N rows and num_arms columns, describing each unit's probabilities of assignment to conditions.$blocks, the blocking variable. \$clusters, the clustering variable.

Examples

# The declare_ra function is used in three ways:

# 1. To obtain some basic facts about a randomization:
declaration <- declare_ra(N=100, m_each=c(30, 30, 40))
declaration#> Random assignment procedure: Complete random assignment
#> Number of units: 100
#> Number of treatment arms: 3
#> The possible treatment categories are T1 and T2 and T3.
#> The probabilities of assignment are constant across units.
# 2. To conduct a random assignment:

Z <- conduct_ra(declaration)
table(Z)#> Z
#> T1 T2 T3
#> 30 30 40
# 3. To obtain observed condition probabilities

probs <- obtain_condition_probabilities(declaration, Z)
table(probs, Z)#>      Z
#> probs T1 T2 T3
#>   0.3 30 30  0
#>   0.4  0  0 40
# Simple Random Assignment Declarations

declare_ra(N=100, simple = TRUE)#> Random assignment procedure: Simple random assignment
#> Number of units: 100
#> Number of treatment arms: 2
#> The possible treatment categories are 0 and 1.
#> The probabilities of assignment are constant across units.declare_ra(N=100, prob = .4, simple = TRUE)#> Random assignment procedure: Simple random assignment
#> Number of units: 100
#> Number of treatment arms: 2
#> The possible treatment categories are 0 and 1.
#> The probabilities of assignment are constant across units.declare_ra(N=100, prob_each=c(0.3, 0.3, 0.4),
conditions=c("control", "placebo", "treatment"), simple=TRUE)#> Random assignment procedure: Simple random assignment
#> Number of units: 100
#> Number of treatment arms: 3
#> The possible treatment categories are control and placebo and treatment.
#> The probabilities of assignment are constant across units.
# Complete Random Assignment Declarations

declare_ra(N=100)#> Random assignment procedure: Complete random assignment
#> Number of units: 100
#> Number of treatment arms: 2
#> The possible treatment categories are 0 and 1.
#> The probabilities of assignment are constant across units.declare_ra(N=100, m_each = c(30, 70),
conditions = c("control", "treatment"))#> Random assignment procedure: Complete random assignment
#> Number of units: 100
#> Number of treatment arms: 2
#> The possible treatment categories are control and treatment.
#> The probabilities of assignment are constant across units.declare_ra(N=100, m_each=c(30, 30, 40))#> Random assignment procedure: Complete random assignment
#> Number of units: 100
#> Number of treatment arms: 3
#> The possible treatment categories are T1 and T2 and T3.
#> The probabilities of assignment are constant across units.

# Block Random Assignment Declarations

blocks <- rep(c("A", "B","C"), times = c(50, 100, 200))

block_m_each <- rbind(c(10, 40),
c(30, 70),
c(50, 150))
declare_ra(blocks = blocks, block_m_each = block_m_each)#> Random assignment procedure: Block random assignment
#> Number of units: 350
#> Number of blocks: 3
#> Number of treatment arms: 2
#> The possible treatment categories are 0 and 1.
#> The probabilities of assignment are NOT constant across units. Your analysis strategy must account for differential probabilities of assignment, typically by employing inverse probability weights.

# Cluster Random Assignment Declarations

clusters <- rep(letters, times = 1:26)
declare_ra(clusters = clusters)#> Random assignment procedure: Cluster random assignment
#> Number of units: 351
#> Number of clusters: 26
#> Number of treatment arms: 2
#> The possible treatment categories are 0 and 1.
#> The probabilities of assignment are constant across units.declare_ra(clusters = clusters, m_each = c(7, 7, 12))#> Random assignment procedure: Cluster random assignment
#> Number of units: 351
#> Number of clusters: 26
#> Number of treatment arms: 3
#> The possible treatment categories are T1 and T2 and T3.
#> The probabilities of assignment are constant across units.
# Blocked and Clustered Random Assignment Declarations

clusters <- rep(letters, times=1:26)
blocks <- rep(NA, length(clusters))
blocks[clusters %in% letters[1:5]] <- "block_1"
blocks[clusters %in% letters[6:10]] <- "block_2"
blocks[clusters %in% letters[11:15]] <- "block_3"
blocks[clusters %in% letters[16:20]] <- "block_4"
blocks[clusters %in% letters[21:26]] <- "block_5"

table(blocks, clusters)#>          clusters
#> blocks     a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w
#>   block_1  1  2  3  4  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>   block_2  0  0  0  0  0  6  7  8  9 10  0  0  0  0  0  0  0  0  0  0  0  0  0
#>   block_3  0  0  0  0  0  0  0  0  0  0 11 12 13 14 15  0  0  0  0  0  0  0  0
#>   block_4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 16 17 18 19 20  0  0  0
#>   block_5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 21 22 23
#>          clusters
#> blocks     x  y  z
#>   block_1  0  0  0
#>   block_2  0  0  0
#>   block_3  0  0  0
#>   block_4  0  0  0
#>   block_5 24 25 26
declare_ra(clusters = clusters, blocks = blocks)#> Random assignment procedure: Blocked and clustered random assignment
#> Number of units: 351
#> Number of blocks: 5
#> Number of clusters: 26
#> Number of treatment arms: 2
#> The possible treatment categories are 0 and 1.
#> The probabilities of assignment are constant across units.declare_ra(clusters = clusters, blocks = blocks, prob_each = c(.2, .5, .3))#> Random assignment procedure: Blocked and clustered random assignment
#> Number of units: 351
#> Number of blocks: 5
#> Number of clusters: 26
#> Number of treatment arms: 3
#> The possible treatment categories are T1 and T2 and T3.
#> The probabilities of assignment are constant across units.