fastrerandomize

An R Package for Fast Rerandomization Using Accelerated Computing

>50x
Faster Processing
100k+
Max Sample Size
GPU
Acceleration

fastrerandomize Released!

Our new R package leverages GPU acceleration and parallel processing to make rerandomization feasible for large-scale experiments with complex balance requirements.

Read the accompanying package paper here.

Features

Designed to make rerandomization accessible for experimental designs at any and all scales.

Accelerated Computation

Employs batched processing, autovectorization, just-in-time-compilation, and (optionally) GPU acceleration to dramatically improve performance (>50x compared to traditional methods).

Learn more

Scale to Any Size

Allows for use in cases where the sample size or number of covariates is very large, making rerandomization practical for modern, large-scale experiments.

Open-Source

Distributed under a GPL-3 license, fastrerandomize is developed and maintained publicly on GitHub.

Balanced Assignment

Generates pools of acceptable randomizations based on a given acceptance probability, ensuring optimal covariate balance across treatment groups.

Tests and Thresholds

Conducts exact rerandomization tests and computes optimal rerandomization acceptance thresholds for reliable statistical inference.

Real-world Applications

Speed ups in applications to economic and geographical experiments, making complex designs accessible to practitioners.

View applications

Example Use

# Step 1: Set up the environment library(fastrerandomize) # Build the backend with Python dependencies build_backend( conda_env = "fastrerandomize", conda = "auto" ) # Step 2: Create some example covariate data set.seed(999L) n <- 1000 X <- matrix(rnorm(n * 5), n, 5) # Step 3: Generate balanced treatment assignments using the main function result <- generate_randomizations( n_units = n, n_treated = n/2, # Number of treated units (50%) X = X, # Covariate matrix randomization_accept_prob = 0.01, # Acceptance probability randomization_type = "monte_carlo" # Use Monte Carlo sampling ) # Examine the results head(result$randomizations) # Treatment assignments summary(result$balance) # Balance statistics plot(result) # Plot distribution of balance measures
# Advanced Monte Carlo Batching library(fastrerandomize) # Create example data with many covariates set.seed(42) n <- 5000 p <- 20 X <- matrix(rnorm(n * p), n, p) # For large datasets, use monte_carlo explicitly result_mc <- generate_randomizations_mc( n_units = n, n_treated = n/2, X = X, randomization_accept_prob = 0.001, # Stricter balance criterion max_draws = 1e6, # Maximum number of randomizations to draw batch_size = 10000, # Process in batches for memory efficiency approximate_inv = TRUE # Use diagonal approximation for speed ) # For faster computation with GPU acceleration # Especially useful for large datasets gpu_result <- generate_randomizations( n_units = n, n_treated = n/2, X = X, randomization_accept_prob = 0.0001, # Very stringent max_draws = 1e6, batch_size = 10000, randomization_type = "monte_carlo", verbose = TRUE # Show progress information )
# Using the randomization test functionality library(fastrerandomize) # 1. Generate covariates set.seed(123) n <- 100 X <- matrix(rnorm(n * 3), n, 3) # 2. Generate candidate randomizations randomizations <- generate_randomizations( n_units = n, n_treated = n/2, X = X, randomization_accept_prob = 0.05, randomization_type = "monte_carlo", max_draws = 10000, batch_size = 1000 ) # 3. Generate a simulated outcome with known effect obsW <- randomizations$randomizations[1,] # Use first randomization true_effect <- 0.5 # True treatment effect obsY <- rnorm(n) + obsW * true_effect # 4. Conduct randomization test test_result <- randomization_test( obsW = obsW, obsY = obsY, X = X, candidate_randomizations = randomizations$randomizations, findFI = TRUE, # Calculate fiducial interval alpha = 0.05 # Significance level ) # 5. Examine test results print(test_result) plot(test_result) # Visualize effect and fiducial interval

Research & Citations

For more information, see the package paper: Connor T. Jerzak, Rebecca Goldstein, Aniket Kamat, Fucheng Warren Zhu. "fastrerandomize: An R Package for Fast Rerandomization Using Accelerated Computing," 2025.

Try fastrerandomize: