GFisher is an R package that provides accurate and computationally efficient methods for computing p-values for a general family of Fisher-type statistics (GFisher), including Fisher’s combination, Good’s statistic, Lancaster’s statistic, and weighted Z-score combinations. It supports flexible weighting schemes and an omnibus procedure that adapts the weights and degrees of freedom to the data. The p-value calculation methods used in the testing procedure are based on moment-ratio matching and joint distribution approximations. The new version includes both pure R implementations and optimized C++ code via RcppArmadillo to improve performance on large-scale data. Based on Zhang, H. and Wu, Z. (2022) ``The generalized Fisher’s combination and accurate p-value calculation under dependence”, Biometrics, 79(2), 1159-1172.
# install.packages("remotes")
remotes::install_github("ZWuLab/GFisher")
# requires a C++ compiler
install.packages("devtools")
devtools::install_local("path/to/GFisher")For optimized calculations under independence (*_ind functions), install the ‘coga’ package:
# Check if coga is available
GFisher::check_coga()
# Install coga from CRAN
install.packages("coga")
# Or use the helper function
GFisher::check_coga(install = TRUE)Note: If ‘coga’ is not installed, you can still perform calculations under independence using the general functions with M = diag(n), though this will be slower than the specialized *_ind functions.
library(GFisher)
# Example: Combine p-values under independence
set.seed(123)
pvals <- c(0.01, 0.03, 0.05, 0.1, 0.2)
# Calculate GFisher statistic (standard Fisher's method: df=2, equal weights)
stat <- stat.GFisher(pvals, df = 2, w = 1)
# Calculate p-value (fast method for independent p-values)
p_value <- p.GFisher_ind_w1(stat, df = rep(2, length(pvals)))
print(p_value)
# Calculate p-value using other functions
p.GFisher_ind(stat, df=rep(2, length(pvals)), w=rep(1, length(pvals)))
p.GFisher(stat, df=2, w=1, M=diag(length(pvals)))
# Example: Account for dependence with correlation matrix
n <- 5
M <- matrix(0.3, n, n) + diag(0.7, n, n) # Correlation matrix
p_dependent <- p.GFisher(stat, df = 2, w = 1, M = M, method = "HYB")
print(p_dependent)GFisher/
├── R/ # R function implementations
├── src/ # C++ source code
├── tests/testthat/ # Unit tests
├── vignettes/ # Documentation and examples
└── inst/ # Additional package files
Version 0.3.0
This version includes fully implemented GFisher methodology with both R and optimized C++ implementations.
Basic GFisher Tests: - stat.GFisher(): Calculate GFisher test statistic - p.GFisher(): Calculate p-value under dependence (methods: HYB, MR, GB)
Omnibus Tests: - stat.oGFisher(): Calculate multiple GFisher statistics with different configurations - pval.oGFisher(): Combined p-value using Cauchy combination or minimum p-value
Independent Case (Optimized, require ‘coga’ package): - p.GFisher_ind(): Fast p-value calculation for independent inputs (requires coga) - p.GFisher_ind_w1(): Fastest method for equal weights (no coga needed) - stat.oGFisher_ind(): Omnibus test for independent inputs (requires coga) - pval.oGFisher_ind(): Combined p-value for independent inputs (requires coga)
Helper Functions: - check_coga(): Check and optionally install ‘coga’ package for independent functions - getGFisherGM(): Calculate covariance of GFisher statistic - getGFisherlam(): Calculate eigenvalues for moment matching - getGFisherCOR(): Calculate correlation among multiple GFisher tests - getGFishercov(): Calculate covariance matrix - getGFishercoef(): Calculate coefficients for variance calculation
vignette("introduction", package = "GFisher") for an introduction?function_name for detailed documentation?GFisher for package overviewThe C++ implementations provide substantial speedups over pure R code:
Recent Optimization (2025-10-16): Refactored getGFisherGM() to eliminate code duplication and integrate with the caching system. Both R and C++ versions now share coefficient calculations, providing: - Eliminated ~80 lines of duplicated code - 2-4x speedup on repeated calls with same degrees of freedom - 30-70% time reduction for typical genomic pipelines analyzing thousands of gene sets - Automatic caching with negligible memory overhead (<2 KB)
For issues or contributions, please file an issue on GitHub or contact the package maintainer.
If you use GFisher in your research, please cite:
Zhang, H. and Wu, Z. (2022). The generalized Fisher's combination and accurate p-value calculation under dependence. *Biometrics*, 79(2), 1159-1172. doi:10.1111/biom.13634
Maintainer: Hong Zhang (consistencyzhang@gmail.com). Please file bugs and questions at https://github.com/ZWuLab/GFisher/issues.
GFisher is also used as the combination-test backend of the GLOW software family.
Developed with AI assistance; see AI-USE.md.