gostevehoward / confseq

Confidence sequences and uniform boundaries
MIT License
54 stars 3 forks source link

Confidence sequences and uniform boundaries

This library supports calculation of uniform boundaries, confidence sequences, and always-valid p-values. These constructs are useful in sequential A/B testing, best-arm identification, and other sequential statistical procedures. The library is written in C++ and Python with a full Python interface and partial R interface. The main references are

This library is in early-stage development and should not be considered stable. Automated tests run on Python 3.7, 3.8, 3.9 and 3.10 on the latest Ubuntu and macOS.

The C++ implementation requires a compiler with C++14 to build the package, as well as the Boost C++ headers.

In the Python package, functions are split across modules by topic, as detailed below. In the R package, all functions mentioned below are exported in a single namespace.

Installing the python package

Run pip install confseq at the command line.

Installing the R package

Run the following in the R console:

install.packages('devtools')
devtools::install_github('gostevehoward/confseq/r_package')

Demos

Estimating average treatment effect in a randomized trial

demo/ate_demo.py illustrates how to compute a confidence sequence for average treatment effect in a randomized trial with bounded potential outcomes, along with an always-valid p-value sequence. The method is based on Corollary 2 of the paper and uses the gamma-exponential mixture boundary. This demo requires numpy and pandas.

Quantile confidence sequences

demo/quantiles.py illustrates how to use some of the included boundaries to construct confidence sequences for quantiles based on a stream of i.i.d. samples. The file includes a function to estimate a single, fixed quantile, as well as a function to estimate all quantiles simultaneously, with error control uniform over quantiles and time.

Uniform boundaries

The confseq.boundaries Python module implements several uniform boundaries from the confidence sequences paper.

All functions accept NumPy arrays in Python or vectors in R and perform vectorized operations.

Quantile bounds

The confseq.quantiles Python module implements two quantile-uniform confidence sequences from the quantile paper.

Finally, quantile_ab_p_value implements the two-sided sequential test of the hypothesis that two populations have equal values for some quantile, based on Theorem 5. The theorem covers tests of null hypothesis other than equality, as well as one-sided tests, but these are not yet implemented.

C++ library

The main underlying implementation is in a single-file, header-only C++ library in src/confseq/uniform_boundaries.h. The top of the file defines a simplified interface mirroring the Python interface described above. Below that is an object-oriented interface useful for more involved work. The confseq.boundaries Python module is a wrapper generated by pybind11. The R package uses Rcpp.

Additional python modules

Some implementations (such as betting-based or without-replacement confidence sequences) are only available in Python at the moment. Specifically, these include the implementations of

If you would like to help create an R interface for these methods, it would be appreciated!

Unit tests

C++

make -C /path/to/confseq/test runtests

Python (with random tests)

pytest --ignore=test/googletest-1.8.1/

Python (without random tests)

pytest -m "not random" --ignore=test/googletest-1.8.1/

Citing this software

Howard, S. R., Waudby-Smith, I. and Ramdas, A. (2019-), ConfSeq: software for confidence sequences and uniform boundaries, https://github.com/gostevehoward/confseq [Online; accessed ].

@Misc{,
  author = {Steven R. Howard, Ian Waudby-Smith, and Aaditya Ramdas},
  title = {{ConfSeq}: software for confidence sequences and uniform boundaries},
  year = {2021--},
  url = "https://github.com/gostevehoward/confseq",
  note = {[Online; accessed <today>]}
}