Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
data8-textbook-zh
提交
006f34e1
D
data8-textbook-zh
项目概览
OpenDocCN
/
data8-textbook-zh
8 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
data8-textbook-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
006f34e1
编写于
1月 20, 2018
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ch16.
上级
2e98068f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
0 deletion
+48
-0
16.md
16.md
+48
-0
未找到文件。
16.md
浏览文件 @
006f34e1
...
...
@@ -353,3 +353,51 @@ Observed TVD: 0.418419465491
### 两个类别分布的相等性的排列检验
我们上面所做的检验被称为原假设的排列检验,即两个样本是从相同的底层分布中抽取的。
为了定义一个执行检验的函数,我们可以复制前一个单元格的代码,并更改表和列的名称。函数
`permutation_test_tvd`
接受数据表的名称,包含类别变量的列标签,它的分布要检验,包含二元类别变量的列标签,以及要运行的随机排列的数量。
在我们上面的例子中,我们没有计算 P 值,因为观测值远离原假设下统计量的分布。但是,一般来说,我们应该计算 P 值,因为在其他例子中统计量可能不是那么极端。 P 值是“假设原假设为真,所得距离大于等于观测距离”的几率,因为备选假设比原假设预测了更大的距离。
```
py
def
permutation_test_tvd
(
table
,
variable
,
classes
,
repetitions
):
"""Test whether a categorical variable is independent of classes:
table: name of table containing the sample
variable: label of column containing categorical variable whose distribution is of interest
classes: label of column containing binary class data
repetitions: number of random permutations"""
# Find the tvd between the distributions of variable in the two classes
counts
=
table
.
select
(
classes
,
variable
).
pivot
(
classes
,
variable
)
observed_tvd
=
tvd
(
proportions
(
counts
.
column
(
1
)),
proportions
(
counts
.
column
(
2
)))
# Assuming the null is true, randomly permute the variable and collect all the new tvd's
tvds
=
make_array
()
for
i
in
np
.
arange
(
repetitions
):
shuffled_var
=
table
.
select
(
variable
).
sample
(
with_replacement
=
False
).
column
(
0
)
shuffled
=
table
.
select
(
classes
).
with_column
(
'Shuffled Variable'
,
shuffled_var
)
shuffled_counts
=
shuffled
.
pivot
(
classes
,
'Shuffled Variable'
)
new_tvd
=
tvd
(
proportions
(
shuffled_counts
.
column
(
1
)),
proportions
(
shuffled_counts
.
column
(
2
)))
tvds
=
np
.
append
(
tvds
,
new_tvd
)
# Find the empirical P-value:
emp_p
=
np
.
count_nonzero
(
tvds
>=
observed_tvd
)
/
repetitions
# Draw the empirical histogram of the tvd's generated under the null,
# and compare with the value observed in the original sample
Table
().
with_column
(
'TVD'
,
tvds
).
hist
(
bins
=
20
)
plots
.
title
(
'Empirical Distribution Under the Null'
)
print
(
'Observed TVD:'
,
observed_tvd
)
print
(
'Empirical P-value:'
,
emp_p
)
permutation_test_tvd
(
patients
,
'Clump Thickness'
,
'Class'
,
5000
)
Observed
TVD
:
0.638310905047
Empirical
P
-
value
:
0.0
```
同样,观测距离 0.64 离原假设预测的分布很远。 经验 P 值为 0,所以准确的 P 值将接近于零。 因此,如果类别和有丝分裂评分是不相关的,那么观测的数据是极不可能的。
所以得出的结论是,有丝分裂评分与类别有关,不仅在样本中,而且在总体中。
我们使用排列检验来帮助我们确定,类别属性的分布是否与类别相关。 一般来说,排列检验可以这样使用来确定,两个类别分布是否从相同的基本分布随机抽样。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录