Name | skmiscpy JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | Contains a few functions useful for data-analysis, causal inference etc. |
upload_time | 2024-08-16 11:04:21 |
maintainer | None |
docs_url | None |
author | Shafayet Khan Shafee |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# skmiscpy
[](https://pypi.org/project/skmiscpy/)   [](https://github.com/shafayetShafee/skmiscpy/actions/workflows/ci-cd.yml) [](https://codecov.io/github/shafayetShafee/skmiscpy)
Contains a few functions useful for data-analysis, causal inference etc.
## Installation
```bash
pip install skmiscpy
```
## Usage
So far, `skmiscpy` can be used to do a basic causal analysis. Here very simple examples are shown for demonstration purposes.
Check [Causal Analysis Workflow & Estimating ATE Using `skmiscpy`](https://skmiscpy.readthedocs.io/en/latest/example.html) for
better understanding.
``` python
import pandas as pd
from skmiscpy import compute_smd, plot_smd
from skmiscpy import plot_mirror_histogram
```
### Draw a mirror histogram
``` python
data = pd.DataFrame({
'treatment': [1, 1, 0, 0, 1, 0],
'propensity_score': [2.0, 3.5, 3.0, 2.2, 2.2, 3.3]
})
plot_mirror_histogram(data=data, var='propensity_score', group='treatment')
# Draw a weighted mirror histogram
data_with_weights = pd.DataFrame({
'treatment': [1, 1, 0, 0, 1, 0],
'propensity_score': [2.0, 3.5, 3.0, 2.2, 2.2, 3.3],
'weights': [1.0, 1.5, 2.0, 1.2, 1.1, 0.8]
})
plot_mirror_histogram(
data=data_with_weights, var='propensity_score', group='treatment', weights='weights',
xlabel='Propensity Score', ylabel='Weighted Count', title='Weighted Mirror Histogram'
)
```
### Compute Standardized Mean Difference (SMD)
```python
sample_df = pd.DataFrame({
'age': np.random.randint(18, 66, size=100),
'weight': np.round(np.random.uniform(120, 200, size=100), 1),
'gender': np.random.choice(['male', 'female'], size=100),
'race': np.random.choice(
['white', 'black', 'hispanic'],
size=100, p=[0.4, 0.3, 0.3]
),
'educ_level': np.random.choice(
['bachelor', 'master', 'doctorate'],
size=100, p=[0.3, 0.4, 0.3]
),
'ps_wts': np.round(np.random.uniform(0.1, 1.0, size=100), 2),
'group': np.random.choice(['treated', 'control'], size=100),
'date': pd.date_range(start='2024-01-01', periods=100, freq='D')
})
# 1. Basic usage with unadjusted SMD only:
compute_smd(sample_df, vars=['age', 'weight', 'gender'], group='group', estimand='ATE')
# 2. Including weights for adjusted SMD:
compute_smd(
sample_df,
vars=['age', 'weight', 'gender'],
group='group', wt_var='ps_wts',
estimand='ATE'
)
# 3. Including categorical variables for adjusted SMD:
compute_smd(
sample_df,
vars=['age', 'weight', 'gender'],
group='group',
wt_var='ps_wts',
cat_vars=['race', 'educ_level'],
estimand='ATE'
)
```
### Create a love plot (point plot of SMD)
``` python
data = pd.DataFrame({
'variables': ['age', 'bmi', 'blood_pressure'],
'unadjusted_smd': [0.25, 0.4, 0.1],
'adjusted_smd': [0.05, 0.2, 0.08]
})
plot_smd(data)
## Adding a reference line at 0.1
plot_smd(data, add_ref_line=True, ref_line_value=0.1)
## Customizing the Seaborn plot with additional keyword arguments
plot_smd(data, add_ref_line=True, ref_line_value=0.1, palette='coolwarm', markers=['o', 's'])
```
## Contributing
Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.
## License
`skmiscpy` was created by Shafayet Khan Shafee. It is licensed under the terms of the MIT license.
## Credits
`skmiscpy` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
Raw data
{
"_id": null,
"home_page": null,
"name": "skmiscpy",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Shafayet Khan Shafee",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/fe/cc/f8466782dfcb58ceb2ff833c96ebbc94bf89ba189ecdd48ccd69db656864/skmiscpy-0.4.0.tar.gz",
"platform": null,
"description": "# skmiscpy\n\n[](https://pypi.org/project/skmiscpy/)   [](https://github.com/shafayetShafee/skmiscpy/actions/workflows/ci-cd.yml) [](https://codecov.io/github/shafayetShafee/skmiscpy)\n\nContains a few functions useful for data-analysis, causal inference etc.\n\n## Installation\n\n```bash\npip install skmiscpy\n```\n\n## Usage\n\nSo far, `skmiscpy` can be used to do a basic causal analysis. Here very simple examples are shown for demonstration purposes.\nCheck [Causal Analysis Workflow & Estimating ATE Using `skmiscpy`](https://skmiscpy.readthedocs.io/en/latest/example.html) for\nbetter understanding.\n\n``` python\nimport pandas as pd\nfrom skmiscpy import compute_smd, plot_smd\nfrom skmiscpy import plot_mirror_histogram\n```\n\n### Draw a mirror histogram\n\n``` python\ndata = pd.DataFrame({\n 'treatment': [1, 1, 0, 0, 1, 0],\n 'propensity_score': [2.0, 3.5, 3.0, 2.2, 2.2, 3.3]\n})\n\nplot_mirror_histogram(data=data, var='propensity_score', group='treatment')\n\n# Draw a weighted mirror histogram\ndata_with_weights = pd.DataFrame({\n 'treatment': [1, 1, 0, 0, 1, 0],\n 'propensity_score': [2.0, 3.5, 3.0, 2.2, 2.2, 3.3],\n 'weights': [1.0, 1.5, 2.0, 1.2, 1.1, 0.8]\n})\n\nplot_mirror_histogram(\n data=data_with_weights, var='propensity_score', group='treatment', weights='weights',\n xlabel='Propensity Score', ylabel='Weighted Count', title='Weighted Mirror Histogram'\n)\n```\n### Compute Standardized Mean Difference (SMD)\n\n```python\nsample_df = pd.DataFrame({\n 'age': np.random.randint(18, 66, size=100),\n 'weight': np.round(np.random.uniform(120, 200, size=100), 1),\n 'gender': np.random.choice(['male', 'female'], size=100),\n 'race': np.random.choice(\n ['white', 'black', 'hispanic'],\n size=100, p=[0.4, 0.3, 0.3]\n ),\n 'educ_level': np.random.choice(\n ['bachelor', 'master', 'doctorate'],\n size=100, p=[0.3, 0.4, 0.3]\n ),\n 'ps_wts': np.round(np.random.uniform(0.1, 1.0, size=100), 2),\n 'group': np.random.choice(['treated', 'control'], size=100),\n 'date': pd.date_range(start='2024-01-01', periods=100, freq='D')\n})\n\n# 1. Basic usage with unadjusted SMD only:\ncompute_smd(sample_df, vars=['age', 'weight', 'gender'], group='group', estimand='ATE')\n\n# 2. Including weights for adjusted SMD:\ncompute_smd(\n sample_df, \n vars=['age', 'weight', 'gender'], \n group='group', wt_var='ps_wts',\n estimand='ATE'\n)\n\n# 3. Including categorical variables for adjusted SMD:\ncompute_smd(\n sample_df,\n vars=['age', 'weight', 'gender'],\n group='group',\n wt_var='ps_wts',\n cat_vars=['race', 'educ_level'],\n estimand='ATE'\n)\n```\n\n### Create a love plot (point plot of SMD)\n\n``` python\ndata = pd.DataFrame({\n 'variables': ['age', 'bmi', 'blood_pressure'],\n 'unadjusted_smd': [0.25, 0.4, 0.1],\n 'adjusted_smd': [0.05, 0.2, 0.08]\n})\n\nplot_smd(data)\n\n## Adding a reference line at 0.1\nplot_smd(data, add_ref_line=True, ref_line_value=0.1)\n\n## Customizing the Seaborn plot with additional keyword arguments\nplot_smd(data, add_ref_line=True, ref_line_value=0.1, palette='coolwarm', markers=['o', 's'])\n\n```\n\n## Contributing\n\nInterested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.\n\n## License\n\n`skmiscpy` was created by Shafayet Khan Shafee. It is licensed under the terms of the MIT license.\n\n## Credits\n\n`skmiscpy` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Contains a few functions useful for data-analysis, causal inference etc.",
"version": "0.4.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "780d613b566f4d69f7b196030b1c0bd624240a2d8160899e4a6677bfc60e0a1e",
"md5": "41eacf1255c9df478bebc45aeb4dab7a",
"sha256": "db0e5a6d9c081b1dd72f4bd1d4ccebee0183028ea8c4bfdd0103a00dd696fa20"
},
"downloads": -1,
"filename": "skmiscpy-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "41eacf1255c9df478bebc45aeb4dab7a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 13800,
"upload_time": "2024-08-16T11:04:19",
"upload_time_iso_8601": "2024-08-16T11:04:19.923763Z",
"url": "https://files.pythonhosted.org/packages/78/0d/613b566f4d69f7b196030b1c0bd624240a2d8160899e4a6677bfc60e0a1e/skmiscpy-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "feccf8466782dfcb58ceb2ff833c96ebbc94bf89ba189ecdd48ccd69db656864",
"md5": "dfd1d7e38073c1b5397e63b568f59c99",
"sha256": "b344d9cec8ce467475896facdaf25a28bb4bc3383eaf393a39f2c4495fe3131b"
},
"downloads": -1,
"filename": "skmiscpy-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "dfd1d7e38073c1b5397e63b568f59c99",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 13281,
"upload_time": "2024-08-16T11:04:21",
"upload_time_iso_8601": "2024-08-16T11:04:21.332062Z",
"url": "https://files.pythonhosted.org/packages/fe/cc/f8466782dfcb58ceb2ff833c96ebbc94bf89ba189ecdd48ccd69db656864/skmiscpy-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-16 11:04:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "skmiscpy"
}