Python statsmodels.stats.multitest.fdrcorrection() Examples
The following are 4
code examples of statsmodels.stats.multitest.fdrcorrection().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
statsmodels.stats.multitest
, or try the search function
.
Example #1
Source File: multicomp.py From vnpy_crypto with MIT License | 6 votes |
def mcfdr(nrepl=100, nobs=50, ntests=10, ntrue=6, mu=0.5, alpha=0.05, rho=0.): '''MonteCarlo to test fdrcorrection ''' nfalse = ntests - ntrue locs = np.array([0.]*ntrue + [mu]*(ntests - ntrue)) results = [] for i in range(nrepl): #rvs = locs + stats.norm.rvs(size=(nobs, ntests)) rvs = locs + randmvn(rho, size=(nobs, ntests)) tt, tpval = stats.ttest_1samp(rvs, 0) res = fdrcorrection_bak(np.abs(tpval), alpha=alpha, method='i') res0 = fdrcorrection0(np.abs(tpval), alpha=alpha) #res and res0 give the same results results.append([np.sum(res[:ntrue]), np.sum(res[ntrue:])] + [np.sum(res0[:ntrue]), np.sum(res0[ntrue:])] + res.tolist() + np.sort(tpval).tolist() + [np.sum(tpval[:ntrue]<alpha), np.sum(tpval[ntrue:]<alpha)] + [np.sum(tpval[:ntrue]<alpha/ntests), np.sum(tpval[ntrue:]<alpha/ntests)]) return np.array(results)
Example #2
Source File: multicomp.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def mcfdr(nrepl=100, nobs=50, ntests=10, ntrue=6, mu=0.5, alpha=0.05, rho=0.): '''MonteCarlo to test fdrcorrection ''' nfalse = ntests - ntrue locs = np.array([0.]*ntrue + [mu]*(ntests - ntrue)) results = [] for i in range(nrepl): #rvs = locs + stats.norm.rvs(size=(nobs, ntests)) rvs = locs + randmvn(rho, size=(nobs, ntests)) tt, tpval = stats.ttest_1samp(rvs, 0) res = fdrcorrection_bak(np.abs(tpval), alpha=alpha, method='i') res0 = fdrcorrection0(np.abs(tpval), alpha=alpha) #res and res0 give the same results results.append([np.sum(res[:ntrue]), np.sum(res[ntrue:])] + [np.sum(res0[:ntrue]), np.sum(res0[ntrue:])] + res.tolist() + np.sort(tpval).tolist() + [np.sum(tpval[:ntrue]<alpha), np.sum(tpval[ntrue:]<alpha)] + [np.sum(tpval[:ntrue]<alpha/ntests), np.sum(tpval[ntrue:]<alpha/ntests)]) return np.array(results)
Example #3
Source File: correct.py From NiMARE with MIT License | 6 votes |
def _transform(self, result): p = result.maps['p'] _, p_corr = mc.fdrcorrection(p, alpha=self.alpha, method=self.method, is_sorted=False) corr_maps = {'p': p_corr} self._generate_secondary_maps(result, corr_maps) return corr_maps
Example #4
Source File: safe.py From safepy with GNU General Public License v3.0 | 5 votes |
def compute_pvalues_by_hypergeom(self, **kwargs): if kwargs: if 'verbose' in kwargs: self.verbose = kwargs['verbose'] if self.verbose: print('Overwriting global settings:') for k in kwargs: print('\t%s=%s' % (k, str(kwargs[k]))) # Make sure that the settings are still valid self.validate_config() if self.verbose: print('Using the hypergeometric test to calculate enrichment...') # Nodes with not-NaN values in >= 1 attribute nodes_not_nan = np.any(~np.isnan(self.node2attribute), axis=1) # -- Number of nodes # n = self.graph.number_of_nodes() # total n = np.sum(nodes_not_nan) # with not-NaN values in >=1 attribute N = np.zeros([self.graph.number_of_nodes(), len(self.attributes)]) + n # -- Number of nodes annotated to each attribute N_in_group = np.tile(np.nansum(self.node2attribute, axis=0), (self.graph.number_of_nodes(), 1)) # -- Number of nodes in each neighborhood # neighborhood_size = np.sum(self.neighborhoods, axis=0)[:, np.newaxis] # total neighborhood_size = np.dot(self.neighborhoods, nodes_not_nan.astype(int))[:, np.newaxis] # with not-NaN values in >=1 attribute N_in_neighborhood = np.tile(neighborhood_size, (1, len(self.attributes))) # -- Number of nodes in each neighborhood and annotated to each attribute N_in_neighborhood_in_group = np.dot(self.neighborhoods, np.where(~np.isnan(self.node2attribute), self.node2attribute, 0)) self.pvalues_pos = hypergeom.sf(N_in_neighborhood_in_group - 1, N, N_in_group, N_in_neighborhood) # Correct for multiple testing if self.multiple_testing: if self.verbose: print('Running FDR-adjustment of p-values...') out = np.apply_along_axis(fdrcorrection, 1, self.pvalues_pos) self.pvalues_pos = out[:, 1, :] # Log-transform into neighborhood enrichment scores (NES) self.nes = -np.log10(self.pvalues_pos)