The nipy.algorithms.statistics.empirical_pvalue module contains a class that fits a Gaussian model to the central part of an histogram, following Schwartzman et al, 2009. This is typically necessary to estimate a FDR when one is not certain that the data behaves as a standard normal under H_0.
The NormalEmpiricalNull class learns its null distribution on the data provided at initialisation. Two different methods can be used to set a threshold from the null distribution: the NormalEmpiricalNull.threshold() method returns the threshold for a given false discovery rate, and thus accounts for multiple comparisons with the given dataset; the NormalEmpiricalNull.uncorrected_threshold() returns the threshold for a given uncorrected p-value, and as such does not account for multiple comparisons.
If we use the empirical normal null estimator on a two Gaussian mixture distribution, with a central Gaussian, and a wide one, it uses the central distribution as a null hypothesis, and returns the threshold following which the data can be claimed to belong to the wide Gaussian:
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import numpy as np
from nipy.algorithms.statistics.empirical_pvalue import NormalEmpiricalNull
x = np.c_[np.random.normal(size=10000),
np.random.normal(scale=4, size=10000)]
enn = NormalEmpiricalNull(x)
enn.threshold(verbose=True)
(Source code, png, hires.png, pdf)
The threshold evaluated with the NormalEmpiricalNull.threshold() method is around 2.8 (using the default p-value of 0.05). The NormalEmpiricalNull.uncorrected_threshold() returns, for the same p-value, a threshold of 1.9. It is necessary to use a higher p-value with uncorrected comparisons.
Class to compute the empirical null normal fit to the data.
The data which is used to estimate the FDR, assuming a Gaussian null from Schwartzmann et al., NeuroImage 44 (2009) 71–82
Initialize an empirical null normal object.
Parameters: | x : 1D ndarray
|
---|
Given a threshold theta, find the estimated FDR
Parameters: | theta : float or array of shape (n_samples)
|
---|---|
Returns: | afp : value of array of shape(n) |
Returns the FDR associated with any point of self.x
Estimate the proportion, mean and variance of a Gaussian distribution for a fraction of the data
Parameters: | left: float, optional :
right: float, optional :
|
---|
Notes
This method stores the following attributes:
Plot the histogram of x
Parameters: | efp : float, optional
alpha : float, optional
bar=1 : bool, optional mpaxes=None: if not None, handle to an axes where the fig : will be drawn. Avoids creating unnecessarily new figures : |
---|
Compute the threshold corresponding to an alpha-level FDR for x
Parameters: | alpha : float, optional
verbose : boolean, optional
|
---|---|
Returns: | theta: float :
|
Compute the threshold corresponding to a specificity alpha for x
Parameters: | alpha : float, optional
verbose : boolean, optional
|
---|---|
Returns: | theta: float :
|
Reference: Schwartzmann et al., NeuroImage 44 (2009) 71–82