Skip to main content

Contains a few functions useful for data-analysis, causal inference etc.

Project description

skmiscpy

Contains a few functions useful for data-analysis, causal inference etc.

Installation

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 for better understanding.

import pandas as pd
from skmiscpy import compute_smd, plot_smd
from skmiscpy import plot_mirror_histogram

Draw a mirror histogram

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)

data = pd.DataFrame({
    'group': [1, 0, 1, 0, 1, 0],
    'age': [23, 35, 45, 50, 22, 30],
    'bmi': [22.5, 27.8, 26.1, 28.5, 24.3, 29.0],
    'blood_pressure': [120, 130, 140, 135, 125, 133],
    'weights': [1.2, 0.8, 1.5, 0.7, 1.0, 0.9]
})

# Compute SMD for 'age', 'bmi', and 'blood_pressure' under ATE estimand
smd_results = compute_smd(data, vars=['age', 'bmi', 'blood_pressure'], group='group', estimand='ATE')

# Compute SMD adjusted by weights
smd_results_with_weights = compute_smd(data, vars=['age', 'bmi', 'blood_pressure'], group='group', wt_var='weights')

print(smd_results)
print(smd_results_with_weights)

Create a love plot (point plot of SMD)

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 and the py-pkgs-cookiecutter template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skmiscpy-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

skmiscpy-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file skmiscpy-0.1.0.tar.gz.

File metadata

  • Download URL: skmiscpy-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.6 Darwin/22.6.0

File hashes

Hashes for skmiscpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 069a731e78d0753e3fc405374a955e74766a02ce333d902df5cd6a0f1e937293
MD5 93dee0b687f437f7049feca4c4bfbffb
BLAKE2b-256 6d43c3c97964bbc370215ff50a6d92292c3815c27fb8b773e3c051b4a0f76587

See more details on using hashes here.

File details

Details for the file skmiscpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: skmiscpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.6 Darwin/22.6.0

File hashes

Hashes for skmiscpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b0299e8af166a28ed1b8202e028ef11ffea91575cc551d7ae15a0b889e07542
MD5 d1b461f071774b283b9a8c986a0f6ab3
BLAKE2b-256 c9d06b2df0d2a50f091ee2c91c97923f357dd1e3084c11648f1f9c5b0061c5d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page