Skip to main content

CalPred (Calibrated Prediction Intervals for Polygenic Scores Across Diverse Contexts)

See companion manuscript github repository for analysis scripts used in the manuscript.

Installation

# calpred calls R packages statmod and Rchoice in fitting the model
Rscript -e "install.packages(c('statmod', 'Rchoice'), repos='https://cran.rstudio.com')"
pip install calpred

Quick example

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import calpred

np.random.seed(42)
n = 1000
pgs = np.random.normal(size=n)
age = np.random.normal(loc=40, scale=10, size=n)
sex = np.random.binomial(n=1, p=0.5, size=n)

y_mean = 8 + pgs * 0.5 + age * -0.2 + sex * 0.5
y_sd = np.sqrt(np.exp(2 + age * -0.03 + sex * 1))
y = np.random.normal(loc=y_mean, scale=y_sd)

df = pd.DataFrame({"intercept": 1, "pgs": pgs, "age": age, "sex": sex, "y": y})

# x and z are the columns for fitting the mean and standard deviation
x = z = df[["intercept", "pgs", "age", "sex"]]
model = calpred.fit(y=df["y"], x=x, z=z)

# prediction mean and [low, high] for 90% prediction interval
df["pred_mean"], df["pred_sd"] = calpred.predict(x=x, z=z, model_fit=model)
df["pred_low"] = df["pred_mean"] - df["pred_sd"] * 1.645
df["pred_high"] = df["pred_mean"] + df["pred_sd"] * 1.645


# show prediction intervals at 5% / 95% quantile of prediction mean
fig, ax = plt.subplots(figsize=(4, 4), dpi=150)
ax.scatter(df["pred_mean"], df["y"], s=4)
ax.axline((0, 0), slope=1, ls="--", color="red")

idx1 = df.sort_values("pred_mean").index[int(n * 0.05)]
idx2 = df.sort_values("pred_mean").index[int(n * 0.95)]

for idx in [idx1, idx2]:
    ax.errorbar(
        x=df.loc[idx, "pred_mean"],
        y=df.loc[idx, "pred_mean"],
        yerr=df.loc[idx, "pred_sd"] * 1.645,
        color="red",
        capsize=3,
        lw=1,
    )
fig.show()

Upload to PyPI (for developers)

python setup.py sdist
twine upload dist/*

Metadata

Release files for calpred 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calpred 0.1.1
File Size Uploaded Provenance
calpred-0.1.1.tar.gz 16.8 kB Without provenance Details

Release files / calpred-0.1.1.tar.gz

Download URL calpred-0.1.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ce5357c615d6d62669055df74b88b3aedbba7c90184e07883fe573b96f36cda1
BLAKE2b-256 checksum
How to use checksums
f87b1d7b11038ae178c382c547af111cfec326e5f13785e575a0adff773e22a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for calpred 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page