Skip to contents

Tests the sharp null hypothesis that a randomized binary treatment had no effect on a variable \(Z\) for any unit, \(Z_i(1) = Z_i(0)\). Under complete randomization the test is exact: the observed statistic is compared with its distribution over random re-assignments of the treatment labels.

Usage

shift_test(
  z,
  treat,
  z_pre = NULL,
  stats = c("mean", "var", "ks"),
  B = 1999,
  block = 250,
  seed = NULL
)

Arguments

z

Numeric vector, the candidate third variable measured after treatment.

treat

Binary treatment (0/1, logical, or a two-level factor).

z_pre

Optional numeric vector, the same variable measured before treatment.

stats

Character vector, any of "mean", "var", "ks". Default all three.

B

Integer, number of random permutations. Default 1999.

block

Integer, permutations processed per block (controls memory). Default 250.

seed

Optional integer seed for reproducibility.

Value

An object of class "shift_test": a list with the combined p.value, the component permutation p-values p.components, the observed component statistics statistic, the group sizes n1 and n0, group means and standard deviations, B, and a method description.

Details

The default statistic combines three components, each sensitive to a different kind of departure: the absolute difference in means, the absolute log ratio of variances, and the Kolmogorov-Smirnov distance between the two empirical distribution functions. The combined statistic is the minimum of the three permutation p-values, and it is calibrated against the same permutations, so the overall test keeps its size. Including the variance and distribution components matters because a treatment can move \(Z\) up for some units and down for others, leaving the mean unchanged; a mean test alone misses such cancelling effects.

If a baseline (pre-treatment) measure of \(Z\) is supplied through z_pre, the test is applied to the residual of z after regressing it on z_pre. Because z_pre is fixed before assignment and the regression does not use the treatment, these residuals are fixed under the sharp null, so the test remains exact and typically gains a great deal of power.

Ties (discrete or Likert-type variables) are handled by evaluating the empirical distribution functions only at the distinct values. Units with a missing value of z, treat, or z_pre are dropped.

A non-significant result is not evidence that the treatment left \(Z\) unchanged; use equivalence_shift for that claim.

References

Montgomery, J. M., Nyhan, B., & Torres, M. (2018). How conditioning on posttreatment variables can ruin your experiment and what to do about it. American Journal of Political Science, 62(3), 760-775.

Blackwell, M., Brown, J. R., Hill, S., Imai, K., & Yamamoto, T. (2025). Priming bias versus post-treatment bias in experimental designs. Political Analysis, 33(4), 361-377.

Examples

set.seed(1)
treat <- rep(0:1, each = 200)
# treatment moves z up for half the units and down for the others
s <- sample(c(-1, 1), 400, replace = TRUE)
z <- rnorm(400) + 0.8 * treat * s
shift_test(z, treat, B = 499, seed = 2)
#> 
#> Randomization test of no effect on Z for any unit (mean, var, ks; min-p combination)
#> 
#>   Treated: n = 200, mean = -0.034, sd = 1.326
#>   Control: n = 200, mean = 0.041, sd = 1.011
#>   Component p-values: mean = 0.550, var = 0.002, ks = 0.066
#>   Combined p-value = 0.006  (B = 499 permutations)
#>