limix.stats.Chi2MixtureΒΆ
- class limix.stats.Chi2Mixture(scale_min=0.1, scale_max=5.0, dof_min=0.1, dof_max=5.0, n_intervals=100, qmax=0.1, tol=0, lrt=None)[source]ΒΆ
Mixture of πΒ² distributions.
Class for evaluation of P values for a test statistic that follows a two-component mixture of chi2
\[p(x) = (1-π)πΒ²(0) + πππΒ²(π).\]Here π is the probability being in the first component and π and π are the scale parameter and the number of degrees of freedom of the second component.
Warning
This class is not production-ready. Keep in mind that this interface is likely to change.
- Parameters
scale_min (float) β Minimum value used for fitting the scale parameter.
scale_max (float) β Maximum value used for fitting the scale parameter.
dofmin (float) β Minimum value used for fitting the dof parameter.
dofmax (float) β Maximum value used for fitting the dof parameter.
qmax (float) β Only the top qmax quantile is used for the fit.
n_interval (int) β Number of intervals when performing gridsearch.
tol (float) β Tolerance of being zero.
Example
>>> from numpy.random import RandomState >>> import scipy as sp >>> from limix.stats import Chi2Mixture >>> >>> scale = 0.3 >>> dof = 2 >>> mixture = 0.2 >>> n = 100 >>> >>> random = RandomState(1) >>> x = random.chisquare(dof, n) >>> n0 = int( (1-mixture) * n) >>> idxs = random.choice(n, n0, replace=False) >>> x[idxs] = 0 >>> >>> chi2mix = Chi2Mixture(scale_min=0.1, scale_max=5.0, ... dof_min=0.1, dof_max=5.0, ... qmax=0.1, tol=4e-3) >>> chi2mix.estimate_chi2mixture(x) >>> pv = chi2mix.sf(x) >>> print(pv[:4]) [0.2 0.2 0.2 0.2] >>> >>> print('%.2f' % chi2mix.scale) 1.98 >>> print('%.2f' % chi2mix.dof) 0.89 >>> print('%.2f' % chi2mix.mixture) 0.20
- __init__(scale_min=0.1, scale_max=5.0, dof_min=0.1, dof_max=5.0, n_intervals=100, qmax=0.1, tol=0, lrt=None)[source]ΒΆ
Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([scale_min,Β scale_max,Β dof_min,Β β¦])Initialize self.
estimate_chi2mixture
(lrt)Estimates the parameters of a chi2 mixture.
sf
(lrt)Computes the p-values from test statistics lrt.