Skip to main content

A Python package providing ports of statistical methods originally implemented in R.

Project description

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.

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

py_qvalue-0.1.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_qvalue-0.1.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file py_qvalue-0.1.1.tar.gz.

File metadata

  • Download URL: py_qvalue-0.1.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.7 Linux/6.17.5-arch1-1

File hashes

Hashes for py_qvalue-0.1.1.tar.gz
Algorithm Hash digest
SHA256 98682021c8f81224280f581effc4af060ab77e6417659f161ed98b1c17600bcf
MD5 e46c03abcddc3fc97f8791dba772bc93
BLAKE2b-256 aba1ee5f768622737b9a9ec1e226b1ca8aae87366bcfbdf062d9e7dd13d3ce3a

See more details on using hashes here.

File details

Details for the file py_qvalue-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_qvalue-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.7 Linux/6.17.5-arch1-1

File hashes

Hashes for py_qvalue-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6200352a022b5627edf6319bca421aa30786883204c915aa163f940b9f901912
MD5 850445982cace71cc65a3515783e2903
BLAKE2b-256 18425ba76df7042ce2b9411966aea930ad5e5df2e49a586fa4fa77f76376eca7

See more details on using hashes here.

Supported by

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