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.

estimate_chi2mixture(lrt)[source]ΒΆ

Estimates the parameters of a chi2 mixture.

Estimates the parameters of a chi2 mixture by fitting the empirical distribution of null test statistic.

Parameters

lrt (array_like) – Null test statistcs.

sf(lrt)[source]ΒΆ

Computes the p-values from test statistics lrt.

Parameters

lrt (array_like) – Test statistics.

Returns

P-values.

Return type

array_like