This Python package provides tools for computing and visualizing the proportion of variance explained by different moderators in a meta-regression model. The package is designed for Rare Variant Association Studies (RVAS), incorporating genetic variant effect sizes, moderator variables, and statistical model fitting.
- Compute weighted sum of squares (SST, SSR_full, SSR_reduced).
- Calculate proportion of variance explained for each moderator.
- Generate bar plots for variance contributions of moderators.
You can install the package locally with:
pip install -e .
or
pip install path/umr-visualizer
import umr_visualizer as uv
Your dataset should be structured as follows:
Gene | Variant ID | Beta | SE Beta | Mod_1 | Mod_2 | Mod_3 | ... |
---|---|---|---|---|---|---|---|
Gene1 | G1 | 0.2 | 0.1 | 1.2 | 0.5 | 1.0 | ... |
Gene1 | G2 | -0.5 | 0.2 | 0.8 | 0.3 | 0.7 | ... |
Gene2 | G3 | 1.3 | 0.15 | 1.1 | 0.6 | 0.8 | ... |
Gene2 | G4 | 0.7 | 0.05 | 0.9 | 0.4 | 0.9 | ... |
# Define moderators
moderators = ["Mod_1", "Mod_2", "Mod_3"]
# Compute proportions of variance explained example
proportions = uv.proportion_variance_explained(df, fitted_values, "Mod1")
```python
uv.plot_proportion_variance_explained(df, fitted_values_full)
uv.sns_proportion_variance_explained(df, fitted_values_full)
uv.sns2_proportion_variance_explained(df, fitted_values_full)
uv.plotly_variance_explained(df, fitted_values_full)
uv.plot_proportion_variance_explained(df, fitted_values_full)
The package follows the meta-regression framework:
-
Weighted Mean
$$\bar{y}_w = \frac{\sum w_i y_i}{\sum w_i}$$ where
$$w_i = \frac{1}{SE_{\beta_i}^2}$$ . -
Total Sum of Squares (SST)
$$SST = \sum w_i (y_i - \bar{y}_w)^2 $$ -
Sum of Squared Residuals (SSR_full & SSR_reduced)
$$SSR_{\text{full}} = \sum w_i (y_i - \hat{y}_i)^2 $$ $$SSR_{\text{reduced}, j} = \sum w_i (y_i - \hat{y}_i^{\text{reduced}})^2 $$ -
Proportion of Variance Explained
$$Proportion_j = \frac{R^2_j}{R^2_{\text{total}}} $$ with
$$R^2_j = \frac{SSR_{\text{reduced}, j} - SSR_{\text{full}}}{SSR_{\text{reduced}, j}} $$
meta_regression_viz/
│
├── meta_regression_viz/
│ ├── __init__.py # Package initializer
│ ├── stats.py # Functions for computing SST, SSR, and proportions
│ ├── plots.py # Functions for plotting variance explained
│
├── setup.py # Installation script
├── README.md # Documentation
├── LICENSE # License file
├── requirements.txt # List of dependencies
└── .gitignore # Ignore unnecessary files
This package is licensed under the MIT License.
- Salma Zainana
- [email protected] +++