Design & analyze randomized experiments (experiment)
Follow the analysis.
Select a node to explore the method
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))
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- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
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)
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- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Inputs & data
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 |
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
The estimate
\hat\tau=\frac{1}{N}\sum_{j}\frac{n_j}{\bar n}\big(\bar Y_{j}^{T}-\bar Y_{j}^{C}\big)\quad(\text{cluster ATE})
⚠️ 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
Discuss the workflow (0)
Log in to join the discussion.