Calculate the covariance matrix for the weighted components \(w_1 T_1, ..., w_n T_n\) of a single GFisher statistic. Automatically uses C++ implementation when available.

getGFisherGM(D, w, M, p.type = "two", use.cpp = TRUE)

Arguments

D

An n-dimensional vector of degrees of freedom.

w

An n-dimensional vector of weights.

M

Correlation matrix of the input Z-scores from which the input p-values were obtained.

p.type

Character string: "two" for two-sided (default), "one" for one-sided input p-values.

use.cpp

Logical, default TRUE. If TRUE, uses fast C++ implementation. Set to FALSE to force pure R implementation.

Value

An \(n \times n\) covariance matrix for the weighted components \(w_1 T_1, ..., w_n T_n\).

Details

Calculate Covariance Matrix for Weighted Components

This function calculates the covariance matrix for the components of a GFisher statistic, which is needed for computing the eigenvalues in the quadratic approximation method.

The covariance matrix is computed using Hermite polynomial expansions:

For two-sided p-values: $$GM_{ij} = \text{Corr}(T_i, T_j) \cdot \sqrt{2d_i} w_i \cdot \sqrt{2d_j} w_j$$

where the correlation is approximated using the coefficients from getGFishercoef.

For one-sided p-values:

Similar formula with additional odd-order terms.

The output of this function is the target covariance matrix \(M\) mentioned in Section 3.4 (Quadratic approximation) of the GFisher paper.

Performance Note: When use.cpp = TRUE (default), this function uses a C++ implementation with composite Gauss-Legendre quadrature for numerical integration, providing substantial speedup over the pure R implementation. The C++ version automatically falls back to R if unavailable.

References

Zhang, H., & Wu, Z. (2023). The generalized Fisher's combination and accurate p-value calculation under dependence. Biometrics, 79(2), 1159-1172. See Theorem 1 and Section 3.4.

Author

Hong Zhang