prob_ra_internal: prob_ra function for single treatments

View source: R/prob_ra.R

prob_ra_internalR Documentation

prob_ra function for single treatments

Description

Binary treatment assigned in blocks blocks with probability prob

Usage

prob_ra_internal(prob = 0.5, blocks = NULL, n = NULL,
  shuffle_blocks = TRUE, shuffle_within_blocks = TRUE, tol = 10)

Arguments

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

Examples

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

macartan/probrand documentation built on Sept. 12, 2023, 2:24 a.m.