Class QuadraticFormPValues

java.lang.Object
edu.cmu.tetrad.search.test.QuadraticFormPValues

public final class QuadraticFormPValues extends Object
Utilities for converting a quadratic-form statistic Q = sum_i lambda_i * Z_i^2, Z_i ~ N(0,1), into a p-value using fast analytic transforms that use the full eigen-spectrum. Intended use (FF-CI / RCIT): - compute stat = n * ||Cxy||_F^2 - compute eig = positive eigenvalues of Cov( vec(RX ⊗ RY) ) - call one of the transforms below: gamma / saddlepoint-LR / davies (optional) Notes: - "Saddlepoint (Lugannani–Rice)" tends to be dramatically more reliable than HBE/LPB4 while staying very fast. - Davies is more "near-exact" but more code (optionally add later).
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    daviesP(double stat, double[] eig)
    Davies/Imhof-style inversion for Q = sum_i lambda_i * Z_i^2 (Z_i~N(0,1)).
    static double
    daviesP(double stat, double[] eig, double epsAbs, int maxEvals, int maxRec)
    Calculates the right-tail p-value P(Q >= stat) using a method from Davies and Imhof.
    static double
    edgeworthP(double stat, double[] eig, boolean useKurtosis)
    Edgeworth / Cornish–Fisher tail.
    static double
    gammaSatterthwaiteP(double stat, double[] eig)
    Gamma (Satterthwaite–Welch) approximation using first two moments.
    static double
    saddlepointLugannaniRiceP(double stat, double[] eig)
    Saddlepoint approximation (Lugannani–Rice) for Q = sum lambda_i * chi^2_1.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • edgeworthP

      public static double edgeworthP(double stat, double[] eig, boolean useKurtosis)
      Edgeworth / Cornish–Fisher tail. useKurtosis = false → HBE useKurtosis = true → LPB4
      Parameters:
      stat - the test statistic
      eig - eigenvalues
      useKurtosis - whether to use kurtosis
      Returns:
      the p-value
    • gammaSatterthwaiteP

      public static double gammaSatterthwaiteP(double stat, double[] eig)
      Gamma (Satterthwaite–Welch) approximation using first two moments. Keep your existing implementation if you prefer; this is here for completeness.
      Parameters:
      stat - the test statistic
      eig - eigenvalues
      Returns:
      the p-value
    • saddlepointLugannaniRiceP

      public static double saddlepointLugannaniRiceP(double stat, double[] eig)
      Saddlepoint approximation (Lugannani–Rice) for Q = sum lambda_i * chi^2_1. Fast (O(m) per evaluation), uses the full spectrum, usually very accurate in tails. Returns right-tail p-value P(Q >= stat).
      Parameters:
      stat - the test statistic
      eig - eigenvalues
      Returns:
      the p-value
    • daviesP

      public static double daviesP(double stat, double[] eig)
      Davies/Imhof-style inversion for Q = sum_i lambda_i * Z_i^2 (Z_i~N(0,1)). This is a self-contained numerical inversion of the characteristic function. In practice it behaves like the “Davies” family of methods (high accuracy when the eigen-spectrum is correct), and is usually much more reliable than HBE/LPB4. Returns right-tail p-value P(Q >= stat). Important notes: - Assumes lambdas are (numerically) nonnegative. Tiny negative values are truncated to 0. - For very small spectra (e.g., 1–3 eigenvalues) the integral can be more oscillatory; in that case saddlepoint-LR often wins on speed + stability.
      Parameters:
      stat - the test statistic
      eig - eigenvalues
      Returns:
      the p-value
    • daviesP

      public static double daviesP(double stat, double[] eig, double epsAbs, int maxEvals, int maxRec)
      Calculates the right-tail p-value P(Q >= stat) using a method from Davies and Imhof.
      Parameters:
      stat - the test statistic
      eig - eigenvalues
      epsAbs - absolute integration tolerance (cdf accuracy target)
      maxEvals - max integrand evaluations
      maxRec - max recursion depth for adaptive Simpson
      Returns:
      the p-value