def get_layered_pvals(df, groupcol, valuecol, subset_by,
pval_method='kruskalwallis'):
"""
Get pvalues for all pairwise combinations in groupcol.
Performs calculating separately for each group in subset_by columns.
In other words, this is a wrapper for groupby(subset_by) + get_all_pvals().
Parameters
----------
df : pandas dataframe
tidy dataframe with labels in `groupcol` and values in `valuecol`
groupcol, valuecol : str
columns in df
subset_by : str
column to group by
pval_method : str {'kruskalwallis', 'ranksums', 'wilcoxon', 'ttest_ind'}
statistical method for comparison. Default is 'kruskalwallis'
Returns
-------
pvals : dict
multi-level dictionary, with outside keys as the unique values in
df[subset_by] and the inner values as in get_all_pvals()
"""
pvals = {}
for s, subdf in df.groupby(subset_by):
pvals[s] = get_all_pvals(subdf, groupcol, valuecol,
method=pval_method)
return pvals
评论列表
文章目录