Randomize treatment (complete, blocked, cluster) and estimate average effects with design-based variance — including cluster-randomized trials.
Input · what goes in
Experimental units with a treatment indicator and outcome (plus optional cluster/block IDs and covariates).
Show data format & exampleHide example
| unit | cluster | Z | Y |
|---|---|---|---|
| 1 | A | 1 | 4.2 |
| 2 | A | 1 | 5.1 |
| 3 | B | 0 | 3.4 |
| 4 | B | 0 | 2.9 |
Pipeline · the recipe
↑ Click any step in the diagram to read its logic, code, assumptions & discussion.
Randomize the treatment
Data preparation — shapes the raw inputs into what the estimator expects.
Draw a complete randomization (here a 50/50 split over 100 units) with known assignment probabilities.
# Install: install.packages("experiment")
library(experiment)
set.seed(1)
z <- randomize(N = 100, ratio = c(0.5, 0.5))
- No comments on this step yet — be the first.
Log in to comment on this step.
Estimate the cluster-randomized ATE
The core estimate — where the causal quantity itself is computed.
ATEcluster estimates the average effect under cluster randomization with the Imai–King–Nall design-based variance.
out <- ATEcluster(Y = Y, Z = Z, grp = cluster, data = mydata)
summary(out)
- No comments on this step yet — be the first.
Log in to comment on this step.
Output · what you get
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
Result · the numbers
⚠️ Unofficial community showcase of experiment (docs). Not affiliated with the authors — all credit to Kosuke Imai & Zhichao Jiang; this summarizes public documentation.
What it does. experiment packages Imai's tools for the full life-cycle of a randomized study: drawing the randomization, and then estimating the average treatment effect with design-based standard errors that respect how units were assigned.
How it works. randomize() produces complete / blocked / cluster assignments with known probabilities. For analysis, ATEcluster() estimates the ATE under cluster randomization using the Imai–King–Nall design-based variance, and companion functions handle noncompliance. Inference comes from the assignment mechanism, not an outcome model.
Assumptions. Known randomization, SUTVA; the cluster estimator assumes clusters were the unit of assignment.
What you get — A randomized assignment vector and a design-based ATE estimate with a standard error and confidence interval.
Example output
Estimated Average Treatment Effect (ATE):
est se ci.lower ci.upper
0.142 0.061 0.022 0.262
Number of clusters: 50
Number of observations: 500

Discussion (0)
Log in to join the discussion.