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)[source]

A class for continuous random variable following a chi2 mixture.

Class for evaluation of P values for a test statistic that follows a two-component mixture of chi2

\[(1-\pi)\chi^2(0) + \pi a \chi^2(d).\]

Here \(\pi\) is the probability being in the first component and \(a\) and \(d\) are the scale parameter and the number of degrees of freedom of the second component.

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.

Examples

>>> 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)[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