鱼群置换试验的实现
permutation_test的Python项目详细描述
它是什么
fisher置换检验的实现。
以下出版物介绍了该测试:
- 费舍尔,R.A.(1935)。实验设计。1935年。奥利弗和博伊德,爱丁堡。
- 恩斯特,医学博士(2004)。排列方法:精确推断的基础。统计科学,19(4),676-685
如何安装
使用pip安装:
$ pip install permutation_test
命令行脚本用法
示例:
permtest [path/to/data.csv] [groups_colname] [reference_group_name] -t [test_group_name]
使用“帮助”获取有关参数的信息:
$ permtest -h usage: permtest [-h] [-t TESTGROUP] input_filepath treatment_column_name referencegroup positional arguments: input_filepath e.g. path/to/my/data.csv, path to csv file with data treatment_column_name name of column in the csv table that specifies the group referencegroup name of the reference group as named in the csv table optional arguments: -h, --help show this help message and exit -t TESTGROUP, --testgroup TESTGROUP name of the test group as named in th csv table. If not defined, test group is determined automatically. -a ALPHA, --alpha ALPHA significance level alpha (between 0 and 1) If not defined, alpha is set to 0.05. -m MULTI_COMP_CORR, --multi_comp_corr MULTI_COMP_CORR perform multiple comparison correction with benjamini hochberg procedure yes/no, If not defined, correction is performed.
csv文件中的数据结构规范
- csv应该包含逗号分隔的值。一个或多个列应包含测量数据。
- 所有列都需要有一个名称,在第一行中指定。
- 一列包含组的名称
示例my_data.csv:
experiment_1 | experiment_2 | experiment_3 | group_names |
---|---|---|---|
1.4 | 3 | 2.5 | condition_2 |
2 | 5 | 2 | condition_1 |
5.6 | 3 | 17 | condition_2 |
9 | 6.5 | 2 | condition_1 |
17 | 5 | 13.0 | condition_1 |
17 | 2 | 13.0 | condition_3 |
12 | 8 | 18.7 | condition_3 |
要对所有实验执行测试,其中condition_1是引用,而condition_2是 测试数据,运行以下命令:
$ permtest my_data.csv group_names condition_1 -t condition_2
通常,将输出保存在文本文件中很方便:
$ permtest my_data.csv group_names condition_1 -t condition_2 > my_test_result.txt
python库使用示例
>>> import permutation_test as p >>> data = [1,2,2,3,3,3,4,4,5] >>> ref_data = [3,4,4,5,5,5,6,6,7] >>> p_value = p.permutation_test(data, ref_data) taking random subsample of size 20000 from 48620 possible permutations nr of mean diffs: 20000 Distribution of mean differences │ * ┼+1.73038 │ * │ * │ * │ * │ * │ │ * │ * │ │ * │ * │ * │ * │ * │ * * * ┼+0.037 * * ───┼*****─***─**─***─**─**─***─**─**─**┼**─***─**─***─**─**─***─**─***─*****┼─── -2.38713 │ +2.39919 mean difference of tested dataset: -2.0 p_value: 0.00345 p_lower_than (probability that mean of test data is not lower than mean of ref data): 0.00345 p_value_greater_than (probability that mean of test data is not greater than mean of ref data): 0.9998 0.0034500000000000121
asccii艺术情节显示了排列的平均差的分布。 ascii艺术绘图是通过[ap](https://github.com/mfouesneau/asciiplot)完成的,这是一个由morgan fouesneau设计的绘图包。
如果可能的组合数大于n_max, 取大小n_组合最大的随机子样本进行直方图计算。
如果detailed为false,则只返回(双面)p_值, 即,数据与参考数据无差异的概率
如果detailed为真,则为 平均差异以dict返回:
历史数据:所有排列的平均差分布 p_值:双面p_值(数据不存在的概率 不同于参考数据) p_值_小于:数据均值不等于 低于参考数据的平均值 p_值_大于:数据均值的概率为 不大于参考数据的平均值
克里斯托夫·莫尔, 图像和数据分析设备/核心设备, 赫尔姆霍兹-格梅因沙夫的Deutsches Zentrum Für神经退行性Erkrankungen E.V.(DZNE) 赫尔姆霍兹协会德国神经退行性疾病中心(DZNE)