Parity with the R packages

The repository contains direct oracle tests against source installations of:

tests/test_r_parity.py invokes Rscript and compares the returned values to the Python implementation. The checks cover complete-assignment marginal probabilities, deterministic potential-outcome fabrication and reveal, HC2 robust OLS, difference-in-means, Lin covariate adjustment, and an end-to-end fixed DeclareDesign pipeline.

R_LIBS_USER=../r-lib uv run pytest tests/test_r_parity.py

The full native and cross-language suite currently contains 20 tests. The estimation tests additionally exercise Formulaic interactions, absorbed fixed effects, direct PyFixest access, and compatibility and canonical IV syntax.

What parity means for random draws

R and NumPy use different generator implementations and sampling algorithms. The same integer seed is therefore not promised to produce the same assignment vector. The relevant contract is the probability law: fixed arm counts, condition probabilities, within-block restrictions, whole-cluster assignment, and reproducibility within each implementation.

Deliberate differences

The Python API uses callables rather than R formulas for fabrication and inquiry evaluation, and it returns Polars frames rather than base R data frames. Regression formulas are Formulaic/PyFixest formulas, so they are substantially richer than the package’s design declarations. Unsupported design operations fail explicitly rather than silently approximating the R implementation.