Skip to main content

Python interface to Empirikos.jl for empirical Bayes methods

Project description

Empyrikos Python Package

Python interface to Empirikos.jl for empirical Bayes methods.

Installation

pip install git+https://github.com/nignatiadis/empyrikos.git

Requirements

  • Python 3.10+
  • Julia 1.10+ (will be automatically installed via JuliaCall if not present)

Quick Start

import empyrikos as eb
import numpy as np

# Example: Empirical partially Bayes t-test
# Generate test data consistent with model assumptions
np.random.seed(42)
n_tests = 100
df = np.full(n_tests, 10)  # degrees of freedom

# True effect sizes: mix of nulls and non-nulls  
true_beta = np.zeros(n_tests)
true_beta[50:] = np.random.normal(0, 1, 50)  # 50 nulls, 50 non-nulls
# True variances from inverse gamma (conjugate prior)
true_sigma_sq = 1.0 / np.random.gamma(2, 1/0.5, n_tests)

# Generate observed data according to model
beta_hat = np.random.normal(true_beta, np.sqrt(true_sigma_sq))
se_hat_squared = true_sigma_sq * np.random.chisquare(df) / df

# Run empirical partially Bayes t-test
result = eb.epb_ttest(
    beta_hat=beta_hat,
    se_hat_squared=se_hat_squared, 
    df=df,
    alpha=0.05
)

print(f"Number of rejections: {result.n_rejected}")
print(f"Adjusted p-values: {result.adj_pvalues[:5]}...")  # first 5

Additional Methods on Results

After running epb_ttest(), the returned EPBTTestResult object provides additional methods:

pvalue_function(beta_hat, se_hat_squared, df)

Compute empirical partially Bayes p-values for new data using the fitted prior from the original analysis.

# Using fitted result to compute p-values for new data
new_pval = result.pvalue_function(beta_hat=1.5, se_hat_squared=0.25, df=10)
print(f"P-value: {new_pval}")

# Multiple new observations
new_pvals = result.pvalue_function(
    beta_hat=[1.5, -0.8, 2.1], 
    se_hat_squared=[0.25, 0.30, 0.18], 
    df=[10, 15, 12]
)
print(f"P-values: {new_pvals}")

se_hat_squared_pdf(se_hat_squared, df)

Compute the marginal probability density function of the variance estimates using the fitted prior.

# Compute PDF at a single point
pdf_val = result.se_hat_squared_pdf(se_hat_squared=0.25, df=10)
print(f"PDF: {pdf_val}")

# Compute PDF at multiple points
pdf_vals = result.se_hat_squared_pdf(
    se_hat_squared=[0.25, 0.30, 0.18], 
    df=[10, 15, 12]
)
print(f"PDF values: {pdf_vals}")

Documentation

For detailed documentation and examples, see the documentation.

License

MIT License - see 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

empyrikos-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

empyrikos-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: empyrikos-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for empyrikos-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cab5d6d246c5f31296539c14e7694a4ede6631e03fcde92075aebd9ca0841043
MD5 cb24dfc0a860a0d5ca257deb5adb5c3c
BLAKE2b-256 65f21d84f6f573e6302e1881558b542b17cfe01e696ef92e78500cb8d86e450c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: empyrikos-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for empyrikos-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 743c5c5cfde63631edfcc00e7cfcc97738caf61c358a98adae412d9a8eab51bf
MD5 b74004582867b44b7af94d78e62b5c7a
BLAKE2b-256 c2ad9b805a1e5d18b7bdf54dd2b2c5c1268e70fa2aaa9e6b19d7ae49dd51e84c

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