Learn R Programming

fastrerandomize (version 0.3)

generate_randomizations_R: Generate randomizations in base R, filtering by Hotelling's T^2 acceptance

Description

Base R function to either do exact enumeration or Monte Carlo random permutations, then keep the fraction whose T^2 is below the acceptance cutoff.

Usage

generate_randomizations_R(
  n_units,
  n_treated,
  X,
  accept_prob,
  random_type,
  max_draws,
  batch_size
)

Value

A list with:

  • randomizations: a matrix (rows = accepted assignments).

  • balance: numeric vector of T^2 values for each accepted assignment.

Arguments

n_units

Integer, total number of units.

n_treated

Integer, number of units to be assigned to treatment.

X

Covariate matrix (n_units x p).

accept_prob

Numeric in [0, 1]: keep the fraction of randomizations that have the lowest T^2 up to this quantile.

random_type

Either "exact" or "monte_carlo".

max_draws

If `random_type="monte_carlo"`, how many permutations to sample.

batch_size

If `random_type="monte_carlo"`, how many permutations to handle per chunk.