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.core 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 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.0.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.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for py_qvalue-0.1.0.tar.gz
Algorithm Hash digest
SHA256 253eaea8d75ad474f08d33796800f3370e5de1e565aed0bbcf80d126bf706ae9
MD5 9bab731b99090e609e0cbc18e0618fd9
BLAKE2b-256 6a418dded3efae9e5d8994884042e4bd5230ae75c6b8f9a57fca1c04e1f4b02d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_qvalue-0.1.0-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.3 Linux/6.14.3-arch1-1

File hashes

Hashes for py_qvalue-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e46fdf7b29649bafda2d60c7c65dcccef1b37d8a0fc1601adab307c6ce32e5dc
MD5 4287f98930d5ef762e8767d89b5c9bfc
BLAKE2b-256 fc643a160a8d1a339b034ee2bb0283c0a6d6e11e3d912ef236212538e7e7fd8f

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