cbps 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cbps/__init__.py +3462 -0
- cbps/constants.py +46 -0
- cbps/core/__init__.py +93 -0
- cbps/core/cbps_binary.py +1943 -0
- cbps/core/cbps_continuous.py +945 -0
- cbps/core/cbps_multitreat.py +1123 -0
- cbps/core/cbps_optimal.py +507 -0
- cbps/core/results.py +1447 -0
- cbps/data/Blackwell.csv +571 -0
- cbps/data/LaLonde.csv +3213 -0
- cbps/data/npcbps_continuous_sim.csv +501 -0
- cbps/data/nsw.csv +723 -0
- cbps/data/nsw_dw.csv +446 -0
- cbps/data/political_ads_urban_niebler.csv +16266 -0
- cbps/data/psid_controls.csv +2491 -0
- cbps/data/psid_controls2.csv +254 -0
- cbps/data/psid_controls3.csv +129 -0
- cbps/data/simulation_dgp1_seed12345.csv +201 -0
- cbps/data/simulation_dgp2_seed12345.csv +201 -0
- cbps/data/simulation_dgp3_seed12345.csv +201 -0
- cbps/data/simulation_dgp4_seed12345.csv +201 -0
- cbps/datasets/__init__.py +78 -0
- cbps/datasets/blackwell.py +112 -0
- cbps/datasets/continuous.py +223 -0
- cbps/datasets/lalonde.py +272 -0
- cbps/datasets/npcbps_sim.py +101 -0
- cbps/diagnostics/__init__.py +101 -0
- cbps/diagnostics/balance.py +760 -0
- cbps/diagnostics/balance_cbmsm_addon.py +162 -0
- cbps/diagnostics/continuous_diagnostics.py +259 -0
- cbps/diagnostics/normality.py +173 -0
- cbps/diagnostics/ocbps_conditions.py +197 -0
- cbps/diagnostics/overlap.py +198 -0
- cbps/diagnostics/plots.py +1193 -0
- cbps/diagnostics/weights_diag.py +205 -0
- cbps/highdim/__init__.py +84 -0
- cbps/highdim/gmm_loss.py +340 -0
- cbps/highdim/hdcbps.py +1078 -0
- cbps/highdim/lasso_utils.py +498 -0
- cbps/highdim/weight_funcs.py +298 -0
- cbps/inference/__init__.py +42 -0
- cbps/inference/asyvar.py +621 -0
- cbps/inference/vcov_outcome.py +217 -0
- cbps/iv/__init__.py +48 -0
- cbps/iv/cbiv.py +2603 -0
- cbps/logging_config.py +45 -0
- cbps/msm/__init__.py +45 -0
- cbps/msm/cbmsm.py +1871 -0
- cbps/msm/rank_diagnostics.py +112 -0
- cbps/nonparametric/__init__.py +58 -0
- cbps/nonparametric/cholesky_whitening.py +232 -0
- cbps/nonparametric/empirical_likelihood.py +339 -0
- cbps/nonparametric/npcbps.py +1036 -0
- cbps/nonparametric/taylor_approx.py +207 -0
- cbps/py.typed +0 -0
- cbps/sklearn/__init__.py +42 -0
- cbps/sklearn/estimator.py +378 -0
- cbps/utils/__init__.py +82 -0
- cbps/utils/formula.py +415 -0
- cbps/utils/helpers.py +378 -0
- cbps/utils/numerics.py +438 -0
- cbps/utils/r_compat.py +109 -0
- cbps/utils/validation.py +224 -0
- cbps/utils/variance_transform.py +483 -0
- cbps/utils/weights.py +586 -0
- cbps-0.2.0.dist-info/METADATA +1090 -0
- cbps-0.2.0.dist-info/RECORD +70 -0
- cbps-0.2.0.dist-info/WHEEL +5 -0
- cbps-0.2.0.dist-info/licenses/LICENSE +661 -0
- cbps-0.2.0.dist-info/top_level.txt +1 -0
cbps/logging_config.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""CBPS package logging configuration.
|
|
2
|
+
|
|
3
|
+
Provides a package-level logger that users can control via standard
|
|
4
|
+
Python logging mechanisms.
|
|
5
|
+
|
|
6
|
+
Examples
|
|
7
|
+
--------
|
|
8
|
+
>>> from cbps import set_verbosity
|
|
9
|
+
>>> set_verbosity(1) # Enable INFO-level progress messages
|
|
10
|
+
>>> set_verbosity(2) # Enable DEBUG-level diagnostics
|
|
11
|
+
>>> set_verbosity(0) # Restore default (WARNING only)
|
|
12
|
+
"""
|
|
13
|
+
import logging
|
|
14
|
+
|
|
15
|
+
# Package-level logger
|
|
16
|
+
logger = logging.getLogger('cbps')
|
|
17
|
+
logger.addHandler(logging.NullHandler()) # No output by default
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def set_verbosity(level: int = 0):
|
|
21
|
+
"""Set CBPS package verbosity level.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
level : int
|
|
26
|
+
0 = WARNING only (default, production)
|
|
27
|
+
1 = INFO (progress messages)
|
|
28
|
+
2 = DEBUG (detailed diagnostics)
|
|
29
|
+
"""
|
|
30
|
+
if level == 0:
|
|
31
|
+
logger.setLevel(logging.WARNING)
|
|
32
|
+
elif level == 1:
|
|
33
|
+
logger.setLevel(logging.INFO)
|
|
34
|
+
else:
|
|
35
|
+
logger.setLevel(logging.DEBUG)
|
|
36
|
+
|
|
37
|
+
# Add console handler if not already present
|
|
38
|
+
has_console = any(
|
|
39
|
+
isinstance(h, logging.StreamHandler) and not isinstance(h, logging.NullHandler)
|
|
40
|
+
for h in logger.handlers
|
|
41
|
+
)
|
|
42
|
+
if not has_console:
|
|
43
|
+
handler = logging.StreamHandler()
|
|
44
|
+
handler.setFormatter(logging.Formatter('[CBPS] %(levelname)s: %(message)s'))
|
|
45
|
+
logger.addHandler(handler)
|
cbps/msm/__init__.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Marginal Structural Models (MSM) Module.
|
|
3
|
+
|
|
4
|
+
This module implements the Covariate Balancing Propensity Score (CBPS)
|
|
5
|
+
methodology for marginal structural models, as developed by Imai and
|
|
6
|
+
Ratkovic (2015). MSMs enable robust causal inference with time-varying
|
|
7
|
+
treatments and confounders in longitudinal settings.
|
|
8
|
+
|
|
9
|
+
Functions
|
|
10
|
+
---------
|
|
11
|
+
CBMSM
|
|
12
|
+
Formula-based interface for MSM weight estimation.
|
|
13
|
+
cbmsm_fit
|
|
14
|
+
Matrix interface for advanced users.
|
|
15
|
+
|
|
16
|
+
Classes
|
|
17
|
+
-------
|
|
18
|
+
CBMSMResults
|
|
19
|
+
Container for fitted weights, coefficients, and diagnostics.
|
|
20
|
+
|
|
21
|
+
Notes
|
|
22
|
+
-----
|
|
23
|
+
The module estimates inverse probability weights by solving a GMM problem
|
|
24
|
+
where moment conditions are derived from the covariate balancing property
|
|
25
|
+
of MSM weights. Key features include:
|
|
26
|
+
|
|
27
|
+
- Time-invariant or time-varying propensity score coefficients
|
|
28
|
+
- Stabilized weights P(T)/P(T|X) for variance reduction
|
|
29
|
+
- Low-rank covariance approximation for computational efficiency
|
|
30
|
+
- Orthogonal moment conditions based on 2^J factorial design framework
|
|
31
|
+
|
|
32
|
+
References
|
|
33
|
+
----------
|
|
34
|
+
Imai, K. and Ratkovic, M. (2015). Robust estimation of inverse probability
|
|
35
|
+
weights for marginal structural models. Journal of the American Statistical
|
|
36
|
+
Association, 110(511), 1013-1023. https://doi.org/10.1080/01621459.2014.956872
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
from cbps.msm.cbmsm import CBMSM, cbmsm_fit, CBMSMResults
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"CBMSM",
|
|
43
|
+
"cbmsm_fit",
|
|
44
|
+
"CBMSMResults",
|
|
45
|
+
]
|