prob_ra_internal | R Documentation |
Binary treatment assigned in blocks blocks with probability prob
prob_ra_internal(prob = 0.5, blocks = NULL, n = NULL,
shuffle_blocks = TRUE, shuffle_within_blocks = TRUE, tol = 10)
prob |
assignment probability of length n |
blocks |
block indicator, of length n |
n |
Number of units |
shuffle_blocks |
logicial defaulting to TRUE randomly reorders blocks before applying sequential_ra |
shuffle_within_blocks |
logicial defaulting to TRUE randomly reorders units within blocks before applying sequential_ra |
tolerance |
parameter for rounding errors |
prob_ra_internal(n = 10)
# For an assignment with prob = .5 and blocks = c(1,1,1,2,2,2) we require exactly 3 units
# chosen each time, though sometimes 1 from block 1 and 2 from block 2 and sometimes the opposite
reps <- replicate(1000, prob_ra_internal(blocks = c(1,1,1,2,2,2)))
apply(reps, 1, mean) # .5 probabilities for each unit
table(apply(reps, 2, sum)) # exactly 3 selected each time
table(apply(reps[1:3,], 2, sum)) # 1 or 2 in block 1 each time
# Same principles hold for non uniform probabilities
reps <- replicate(1000, prob_ra_internal(blocks = c(1,1,1,2,2,2), prob = (1:6)/6))
apply(reps, 1, mean) # .5 probabilities for each unit
table(apply(reps, 2, sum)) # 3 or 4 selected each time
table(apply(reps[1:3,], 2, sum)) # 1 in block 1 each time
# Probabilities > 1 allowed
prob_ra_internal(blocks = c(1,1,1,2,2,2), prob = (1:6)) # No randomization needed
prob_ra_internal(blocks = c(1,1,1,2,2,2), prob = (1:6)/2) # Randomization needed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.