https://github.com/bayer-group/pybalance
A library for minimizing the effects of confounding covariates
https://github.com/bayer-group/pybalance
beat-undefined confounding machine-learning python statistical-analysis
Last synced: 3 months ago
JSON representation
A library for minimizing the effects of confounding covariates
- Host: GitHub
- URL: https://github.com/bayer-group/pybalance
- Owner: Bayer-Group
- License: bsd-3-clause
- Created: 2023-08-23T11:43:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-28T09:56:03.000Z (8 months ago)
- Last Synced: 2025-09-09T14:01:36.266Z (4 months ago)
- Topics: beat-undefined, confounding, machine-learning, python, statistical-analysis
- Language: Jupyter Notebook
- Homepage:
- Size: 33.2 MB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README

## Confounding Adjustment
In scientific experiments, researchers aim to identify cause and effect by
holding all variables except one constant. Any difference in outcome can then
be attributed to the manipulated variable.
However, in many practical cases, it is not possible to control the variables
of interest. For instance, it is unethical to conduct a randomized trial to test
the effects of smoking on long-term health outcomes; yet the answer to this
question is of extreme interest to policy makers, insurance companies and
regulatory agencies. Similarly, in social science research, when studying the
impact of education on income, researchers cannot manipulate individuals' education
levels while holding all other variables constant.
In these cases, observational data can form the basis for "natural experiments" but
care must be taken in interpreting these data. One major issue with interpreting these
data is known as "confounding".
A classic example of confounding is the association between coffee consumption and
heart disease. Initially, a study might find a positive correlation between high
coffee consumption and increased risk of heart disease. However, this apparent
relationship could be confounded by the fact that heavy coffee drinkers are more
likely to also smoke, which is a known risk factor for heart disease. In this case,
smoking acts as a confounding variable, as it distorts the true relationship between
coffee consumption and heart disease. To address this, researchers need to adjust for
smoking status and potentially other relevant variables to accurately assess the
independent impact of coffee consumption on heart disease risk.
In general, any comparative analysis of two non-randomized populations will differ
systematically in a number of covariate dimensions and these systematic differences
must be adjusted for as part of any causal inference analysis. That is where
`pybalance` comes in.
## PyBalance
`pybalance` is a suite of tools in python for performing confounding adjustment
in non-randomized populations. In `pybalance`, we start with measures of "balance"
(how similar two populations are) and directly optimize this metric. This approach is
different, and we think almost always better, from the well-known propensity score
approach, in which the probability of treatment assignment is modelled, but balance metrics
are almost always anyway implicitly defining the success criterion
(see our [demo](https://bayer-group.github.io/pybalance/demos/ps_matcher.html)).
Our approach here is to explicitly define and directly optimize the balance metric that
is relevant for the given problem.
The `pybalance` library implements several routines for optimizing balance. To learn more
about these methods, head on over to the
[demos](https://bayer-group.github.io/pybalance/02_demos.html). Then give
the code a spin for yourself by following the
[installation instructions](https://bayer-group.github.io/pybalance/01_installation.html).
Any questions or issues please feel free to open an [issue](https://github.com/Bayer-Group/pybalance/issues)
or start a [discussion](https://github.com/Bayer-Group/pybalance/discussions).
An application of this library to build an external control arm in a pharmaceutical
setting is presented [here](https://onlinelibrary.wiley.com/doi/10.1002/pst.2352).
## Features
- Implements linear and non-linear optimization approaches for matching.
- Utilizes integer program solvers and evolutionary solvers for optimization.
- Includes implementation of propensity score matching for comparison.
- Offers a variety of balance calculators and matchers.
- Provides visualization tools for analysis.
- Supports simulation of datasets for testing and demonstration purposes.
## Limitations
At the moment, `pybalance` only implements matching routines. Suport for weighting
methods is on our roadmap and will appear in a future release.
## Citation
If you use `pybalance` for your research, please acknowledge this with a citation to
our [paper](https://onlinelibrary.wiley.com/doi/10.1002/pst.2352).