StatsOtter Causal inference workflows
11
Workflow·2 steps

Random assignment by design (randomizr)

Summary by StatsOtter

Reproducible random assignment — simple, complete, block, cluster, stratified — with the exact assignment probabilities design-based inference needs.

1

Input · what goes in

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
2

Pipeline · the recipe

↑ Click any step in the diagram to read its logic, code, assumptions & discussion.

1
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 from the input data 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)
  • No comments on this step yet — be the first.
2
Estimation

Block-randomize and recover probabilities

The core estimate — where the causal quantity itself is computed.

What happens here

block_ra assigns treatment within each block; block_ra_probabilities returns the exact assignment probabilities.

Formula
\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)
Reads from #1 Feeds into the final output
Key code
Z    <- block_ra(blocks = blocks)
prob <- block_ra_probabilities(blocks = blocks)
table(blocks, Z)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
3

Output · what you get

Block-randomized assignment: balanced treated/control counts within every stratum, with known assignment probabilities.
Fig 1Block-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.

Result · the numbers

\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)

⚠️ 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

Discussion (0)

  • No comments yet — start the conversation.