A collection of methods for computing the cdf of a weighted sum of chi-squared random variables.
Likely abandoned. No release or commit for years (last release over 5 years ago).
pip install momentchi2momentchi2
A Python implementation of three approximate methods for computing the cumulative distribution function of a weighted sum of chi-squared random variables. All the methods are based on moment-matching techniques.
Methods
Based on the R package momentchi2, this Python version contains the following methods:
- Hall-Buckley-Eagleson (function
hbe) - Satterthwaite-Welch (function
sw) - Wood's F method (function
wf) - Lindsay-Pilla-Basak method (function
lpb4)
Installation instructions
Install using pip:
python3 -m pip install momentchi2
Package dependencies
The packages numpy and scipy are required to be installed.
Which method should I use?
All four methods (sw, hbe, wf and lpb4) are good,
but the Hall-Buckley-Eagleson method is recommended for situations
where the number of coefficients is modertately large
(say, greater than 100). For a smaller number of coefficients (e.g. up to 10),
the Lindsay-Pilla-Basak method is recommended.
See Bodenham and Adams (2016) for a detailed analysis.
Examples:
## Hall-Buckley-Eagleson method
from momentchi2 import hbe
# should give value close to 0.95, actually 0.94908
hbe(coeff=[1.5, 1.5, 0.5, 0.5], x=10.203)
# x is a list, output approx. 0.05, 0.95
hbe([1.5, 1.5, 0.5, 0.5], [0.627, 10.203])
# x is a numpy array - preferred approach for speed
import numpy as np
from momentchi2 import hbe
hbe( np.array([1.5, 1.5, 0.5, 0.5]), np.array([0.627, 10.203]) )
# Other methods, e.g. sw, wf or lpb4
# All methods called: methodname(coeff, x)
from momentchi2 import sw
sw([1.5, 1.5, 0.5, 0.5], [0.627, 10.203])
from momentchi2 import wf
wf([1.5, 1.5, 0.5, 0.5], [0.627, 10.203])
from momentchi2 import lpb4
lpb4([1.5, 1.5, 0.5, 0.5], [0.627, 10.203])
# for a larger number of coefficients in coeff vector,
# can increase the number of moments p for improved accuracy.
# NOTE: we need len(coeff) >= p. Default value of p is p=4.
lpb4([0.1, 2.3, 3.4, 5.6, 7.8, 8.9, 9.1], [9.366844, 82.0018], p=6)
Details
All methods take two input arguments:
coeff: a list of the coefficients of the weighted sum (where all values must be strictly greater than 0), andx: the quantile value(s) at which point(s) the cumulative distribution function is computed.