本文整理匯總了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)