Skip to main content

py-qvalue

A Python package for estimating q-values and controlling the False Discovery Rate (FDR), based on the functionalities of the renowned R package qvalue.

Overview

py-qvalue brings key methods from the R qvalue package to the Python ecosystem. It is designed for researchers and analysts who perform multiple hypothesis testing and need robust ways to estimate the proportion of true null hypotheses ($\pi_0$), calculate q-values, and estimate local false discovery rates (lfdr).

This package currently provides Python implementations of the core qvalue and pi0est functions, along with the necessary lfdr calculation, allowing for straightforward FDR control within your Python workflows.

Installation

You can install py-qvalue using pip:

pip install py-qvalue

Quick Start

A basic example demonstrating how to use py-qvalue to calculate q-values from a set of p-values:

import numpy as np
from py_qvalue import qvalue

# Parameters
n_tests = 1000
effect_size = 0.3
null_proportion = 0.9

# Generate null (uniform) and signal (skewed low) components
n_null = int(n_tests * null_proportion)
n_signal = n_tests - n_null

null_p = np.random.uniform(0, 1, n_null)
signal_p = np.random.beta(1, 15, n_signal)  # Stronger signal = more left skew

# Combine and shuffle
p_values = np.concatenate([null_p, signal_p])
np.random.shuffle(p_values)

# Calculate q-values
qvalue_results = qvalue(p_values)

# Access the q-values
q_values = qvalue_results['qvalues']
print("P-values:", p_values[0:10]) # Just the first ten
print("Q-values:", q_values[0:10])

# Access the estimated proportion of true null hypotheses (pi0)
pi0_estimate = qvalue_results['pi0']
print("Estimated pi0:", pi0_estimate)

# Get significant results at a specific FDR level (e.g., 10%)
results_at_fdr = qvalue(p_values, fdr_level=0.10)
significant_mask = results_at_fdr['significant']
print("Significant at 10% FDR:", significant_mask)

Implemented Functions

As a port of qvalue, we use the same core functions includes:

  • qvalue(p, fdr_level=None, pfdr=False, lfdr_out=True, pi0=None, **kwargs): Estimates q-values and related FDR quantities from a set of p-values.
  • pi0est(p, lambda_=None, pi0_method="smoother", smooth_df=3, smooth_log_pi0=False, **kwargs): Estimates the proportion of true null hypotheses ($\pi_0$).
  • lfdr(p, pi0, trunc=True, monotone=True, transf="probit", adj=1.5, eps=1e-8, **kwargs): Estimates local false discovery rates (lfdr).

Users can import qvalue and pi0est from this package.

from py_qvalue import pi0est, qvalue

Relationship to the R qvalue Package

This package is a Python port inspired by and aiming to replicate the functionality of the original qvalue package for R, developed by John D. Storey and colleagues. The R qvalue package is a widely cited and respected tool for false discovery rate control in multiple hypothesis testing.

For more information on the statistical methods and the original R implementation, please refer to:

Contributing

We welcome contributions to py-qvalue! If you find a bug, have a feature request, or want to contribute code, please feel free to open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the GPL v3 License. See the LICENSE file for details.

Metadata

Release files for py-qvalue 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 py-qvalue 0.1.1
File Size Uploaded
py_qvalue-0.1.1.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-qvalue 0.1.1
File Interpreter ABI Platform
py_qvalue-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.6 kB

Release files / py_qvalue-0.1.1.tar.gz

Download URL py_qvalue-0.1.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
98682021c8f81224280f581effc4af060ab77e6417659f161ed98b1c17600bcf
BLAKE2b-256 checksum
How to use checksums
aba1ee5f768622737b9a9ec1e226b1ca8aae87366bcfbdf062d9e7dd13d3ce3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.13.7 Linux/6.17.5-arch1-1

Release files / py_qvalue-0.1.1-py3-none-any.whl

Download URL py_qvalue-0.1.1-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6200352a022b5627edf6319bca421aa30786883204c915aa163f940b9f901912
BLAKE2b-256 checksum
How to use checksums
18425ba76df7042ce2b9411966aea930ad5e5df2e49a586fa4fa77f76376eca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.13.7 Linux/6.17.5-arch1-1

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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