Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 078
Research workflow/2 steps

Random assignment by design (randomizr)

01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 2 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 2
01
Data prep

Define the blocks

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Set up strata (blocks) within which treatment will be balanced.

Reads fromNot specified Feeds into#2
Key code
# Install:  install.packages("randomizr")
library(randomizr)
blocks <- rep(c("A", "B"), each = 5)

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.

Questions to explore
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

The number of units (and optional block/cluster IDs and target sizes).

Show data format & exampleHide example
unit block
1 A
2 A
3 B
4 B
03
Read the evidence

Results & interpretation

1 figure Workflow discussion 0
01FigureBlock-randomized assignment: balanced treated/control counts within every stratum, with known assignment probabilities.

Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.

The estimate

\pi_i=\Pr(Z_i=1),\qquad \hat\tau_{\mathrm{HT}}=\frac1N\sum_i\Big(\frac{Z_i Y_i}{\pi_i}-\frac{(1-Z_i)Y_i}{1-\pi_i}\Big)

Context & interpretation

⚠️ Unofficial community showcase of randomizr (docs). Not affiliated with the authors — all credit to Alexander Coppock & Jasper Cooper (DeclareDesign); this summarizes public documentation.

What it does. randomizr generates the random-assignment procedures that underpin design-based causal inference (the assignment mechanisms whose finite-population properties Peng Ding studies — blocking, complete randomization, rerandomization-compatible designs).

How it works. Functions like complete_ra(), block_ra() and cluster_ra() draw assignments with exactly controlled probabilities, and the matching *_probabilities() functions return each unit's assignment probability — the inverse-probability weights and design information needed for unbiased Neyman/Horvitz–Thompson estimation and randomization inference.

Assumptions. None statistical — it is the assignment mechanism; correct use makes the design known and replicable.

Implements design-based tools associated with Prof. Ding's work; package authored by the DeclareDesign team.

What you get — A reproducible assignment vector plus the exact per-unit assignment probabilities for design-based estimation.

Example output

      Z
blocks 0 1
     A 2 3
     B 3 2

Links: package · paper

Peer notes

Discuss the workflow (0)

  • No comments yet — start the conversation.
IN THE MARGINS

Peer discussion