
Minimum Detectable Effect (MDE) Calculator
mde_calc.RdComputes the Minimum Detectable Effect (MDE) for a range of experimental designs including simple two-sample t-tests, DiD, RD, and clustered randomized trials. Also produces power curves for visualization.
Usage
mde_calc(
n,
per_arm = FALSE,
design = c("ttest", "did", "rd", "cluster"),
sd = 1,
alpha = 0.05,
power = 0.8,
two_sided = TRUE,
icc = 0,
cluster_size = 1,
r2 = 0,
kappa = 1,
plot = TRUE
)Arguments
- n
Numeric. Total sample size (or sample per arm if
per_arm = TRUE).- per_arm
Logical. If
TRUE,nis interpreted as sample per arm. DefaultFALSE.- design
Character. Experimental design:
"ttest"(default),"did","rd","cluster".- sd
Numeric. Standard deviation of the outcome. Default
1.- alpha
Numeric. Type I error rate. Default
0.05.- power
Numeric. Desired power. Default
0.80.- two_sided
Logical. Whether the test is two-sided. Default
TRUE.- icc
Numeric. Intraclass correlation for cluster designs. Default
0.- cluster_size
Integer. Average cluster size. Default
1.- r2
Numeric. R-squared of covariates (variance reduction from regression adjustment). Default
0(no adjustment).- kappa
Numeric. Ratio of control to treated observations (1 = equal sizes, 2 = twice as many controls). Default
1.- plot
Logical. Whether to produce a power curve. Default
TRUE.
Value
A list with:
- mde
Numeric. Minimum detectable effect (in outcome units).
- mde_std
Numeric. Standardized MDE (Cohen's d).
- design_effect
Numeric. Design effect from clustering.
- effective_n
Numeric. Effective sample size after design effect.
- plot
ggplot2 power curve, or
NULLifplot = FALSE.
Details
The MDE is the smallest true effect that would be detected with probability
power at significance level alpha:
$$MDE = (t_{1-\alpha/2} + t_{1-\beta}) \cdot SE(\hat{\tau})$$
For clustered designs, the design effect is: $$DEFF = 1 + (\bar{m} - 1)\rho$$ where \(\bar{m}\) is the average cluster size and \(\rho\) is the ICC.