本文整理汇总了Python中statsmodels.stats.multitest.fdrcorrection方法的典型用法代码示例。如果您正苦于以下问题:Python multitest.fdrcorrection方法的具体用法?Python multitest.fdrcorrection怎么用?Python multitest.fdrcorrection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.stats.multitest
的用法示例。
在下文中一共展示了multitest.fdrcorrection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mcfdr
# 需要导入模块: from statsmodels.stats import multitest [as 别名]
# 或者: from statsmodels.stats.multitest import fdrcorrection [as 别名]
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)
示例2: _transform
# 需要导入模块: from statsmodels.stats import multitest [as 别名]
# 或者: from statsmodels.stats.multitest import fdrcorrection [as 别名]
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
示例3: compute_pvalues_by_hypergeom
# 需要导入模块: from statsmodels.stats import multitest [as 别名]
# 或者: from statsmodels.stats.multitest import fdrcorrection [as 别名]
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)