Python library of Dynamic Treatment Regimes
Project description
pydtr
Description
This is a python library to conduct a dynamic treatment regime (DTR), pydtr
.
A DTR is a paradigm that attempts to select optimal treatments adaptively for individual patients.
Pydtr enables you to implement DTR methods easily by using sklearn-based interfaces.
Method | Single binary treatment | Multiple treatments | Multinomial treatment | Continuous Treatment |
---|---|---|---|---|
IqLearnReg (with sklearn) |
:white_check_mark: | :white_check_mark: | :white_check_mark: (with ordinal encoded treatment) |
|
IqLearnReg (with statsmodels) |
:white_check_mark: | :white_check_mark: | :white_check_mark: | |
GEstimation | WIP | WIP | WIP |
IqLearnReg
means a regression method of iterative q-learning.
When a treatment variable is multinomial and you use a sklearn model as a regression function, you need to encode the treatment variable by an ordinal encoding and use a tree-based sklearn model.
G-estimation, a famous method of DTR, is now unavailable.
Requirement
- python (>= 3.6)
- pip
Install
pip install pydtr
Usage
Iterative Q Learning (IqLearnReg)
You need to import libraries and prepare data.
# import
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from pydtr.iqlearn.regression import IqLearnReg
# create sample dataframe
n = 10
thres = int(n / 2)
df = pd.DataFrame()
df["L1"] = np.arange(n)
df["A1"] = [0, 1] * int(n / 2)
df["A2"] = [0] * int(n / 2) + [1] * int(n / 2)
df["Y1"] = np.zeros(n)
df["Y2"] = np.zeros(n)
You can use sklearn-based models.
# set model info
model_info = [
{
"model": RandomForestRegressor(),
"action_dict": {"A1": [0, 1]},
"feature": ["L1", "A1"],
"outcome": "Y1"
},
{
"model": RandomForestRegressor(),
"action_dict": {"A2": [0, 1]},
"feature": ["L1", "A1", "Y1", "A2"],
"outcome": "Y2"
}
]
# fit model
dtr_model = IqLearnReg(
n_stages=2,
model_info=model_info
)
dtr_model.fit(df)
# predict optimal atcions
opt_action_stage_1 = dtr_model.predict(df, 0)
opt_action_stage_2 = dtr_model.predict(df, 1)
opt_action_all_stages = dtr_model.predict_all_stages(df)
You can also use statsmodels-based models.
# set model info
model_info = [
{
"model": "p_outcome ~ L1 * A1",
"action_dict": {"A1": [0, 1]},
"feature": ["L1", "A1"],
"outcome": "Y1"
},
{
"model": "p_outcome ~ L1 + A1 + Y1 * A2",
"action_dict": {"A2": [0, 1]},
"feature": ["L1", "A1", "Y1", "A2"],
"outcome": "Y2"
}
]
# fit model
dtr_model = IqLearnReg(
n_stages=2,
model_info=model_info
)
dtr_model.fit(df)
# predict optimal atcions
opt_action_stage_1 = dtr_model.predict(df, 0)
opt_action_stage_2 = dtr_model.predict(df, 1)
opt_action_all_stages = dtr_model.predict_all_stages(df)
Authors
Contributors
Please feel free to create issues or to send pull-requests!
If all checkes have passed in pull-requests, I will merge and release them.
License
Structure
├── .circleci
│ ├── config.yml
├── .github
│ ├── CODEOWNERS
├── LICENSE
├── MANIFEST.IN
├── Makefile
├── README.md
├── setup.cfg
├── setup.py
├── src
│ ├── pydtr
│ │ ├── __init__.py
│ │ └── iqlearn
│ │ ├── __init__.py
│ │ ├── base.py
│ │ └── regression.py
└── tests
├── test_iqlearn_sklearn_predict.py
└── test_iqlearn_sm_predict.py
References
- Chakraborty, Bibhas. Statistical methods for dynamic treatment regimes. Springer, 2013.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydtr-0.0.1.tar.gz
.
File metadata
- Download URL: pydtr-0.0.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1b74298f5f681174366a4ebf5f3e86ffb3c59925098ccfe4df51b31aff09e86 |
|
MD5 | 8159ce8c5e2c031e9a99e11f06f144c9 |
|
BLAKE2b-256 | 296632c72c49a004122236932250168a4d07993ce70fe35887bf9a151bac9e87 |
File details
Details for the file pydtr-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pydtr-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b56ab548dfa0cc013788cfe1f70c88b6b59b0d9b23af2a5a615f8f1af0f99dfd |
|
MD5 | 5de8a5fe55d928a3b3e6e675a99b0d30 |
|
BLAKE2b-256 | 23cc8be452ab8e34906bd57b6942750c82815d136dcfb3bbab4c8fe74ddc0230 |