Skip to contents

Conducts Fisher's randomization inference (permutation test) for causal effects, computing sharp null p-values and visualizing the randomization distribution. Also supports in-time and in-space placebo tests.

Usage

placebo_test(
  data,
  outcome,
  treatment,
  estimator = "ate",
  unit_var = NULL,
  time_var = NULL,
  post_var = NULL,
  n_perms = 1000,
  test_stat = c("mean", "t"),
  two_sided = TRUE,
  seed = 42,
  plot = TRUE
)

Arguments

data

A data frame.

outcome

Character. Name of the outcome variable.

treatment

Character. Name of the binary treatment indicator.

estimator

Function or character. The estimator to use: "ate" (default, difference in means), "did" (difference-in-differences requires time_var), or a custom function f(data, outcome, treatment, ...) returning a scalar.

unit_var

Character. Unit identifier (for panel/DiD). Default NULL.

time_var

Character. Time period variable (for DiD). Default NULL.

post_var

Character. Binary indicator for post-treatment period (for DiD). Default NULL.

n_perms

Integer. Number of permutations. Default 1000.

test_stat

Character. Test statistic: "mean" (difference in means) or "t" (t-statistic). Default "mean".

two_sided

Logical. Two-sided p-value. Default TRUE.

seed

Integer. Random seed. Default 42.

plot

Logical. Whether to plot the permutation distribution. Default TRUE.

Value

A list with:

observed_stat

Numeric. Observed test statistic.

p_value

Numeric. Randomization inference p-value.

perm_dist

Numeric vector of permuted test statistics.

plot

ggplot2 histogram of the permutation distribution.

References

Fisher, R. A. (1935). The Design of Experiments. Oliver & Boyd.

Imbens, G. W., & Rubin, D. B. (2015). Causal Inference for Statistics, Social, and Biomedical Sciences. Cambridge University Press.

Examples

set.seed(42)
df <- data.frame(
  Y = c(rnorm(50, mean = 0.5), rnorm(50, mean = 0)),
  D = c(rep(1, 50), rep(0, 50))
)
result <- placebo_test(data = df, outcome = "Y", treatment = "D")
result$p_value
#> [1] 0.083
result$plot