我想从多级别分类数据集创建一个用于 Chisq 测试的 2X2 表
我有一个比赛和结果的数据集(Y,N),我想列出一个 2X2 表来为每场比赛运行 chisq 测试。
Asian 584 24
Black 1721 56
Hispanic 2400 90
White 8164 289
一旦我创建了一个 2X2 的表,那么第一行将是亚洲人,第二行将是非亚洲人(根据总计 - asianNo)和(总计 - asian yes)的值计算,作为该行的第二列。 然后,一旦我对所有比赛重复该过程,我就可以轻松地在每场比赛中运行 chisq 测试。有没有更简单的方法来对上表中的每场比赛运行 Chisq 测试?
I have a dataset of race and outcome either (Y,N) I want to tabulate a 2X2 table to run a chisq test for each race.
Asian 584 24
Black 1721 56
Hispanic 2400 90
White 8164 289
Once I create a table 2X2 so the first row will be Asian and second row will be non-Asian (counted from values of total - asianNo) and (total- asian yes) as the second column of that row.
Then I can run a chisq test easily on each race once I repeat that process for all races. Is there an easier way to run a Chisq test for each race in my table above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果
d
是您的数据,那么下面将生成 2x2 表的列表,然后您可以将 chi-sq 测试应用于每个
输入:
If
d
is your data, then the below will produce your list of 2x2 tablesYou can then apply the chi-sq test to each
Input:
这是
map2
的一个选项,其中第一行是个人比赛,第二行是其他比赛,然后我根据特定比赛命名每个列表。输出
数据
Here is one option with
map2
, where the first row is an individual race and the second row are the others, then I name each list according to the specific race.Output
Data
这是另一种方法。首先设置主表:
现在有一个函数从
Tbl
中的一行创建2x2表:最后创建卡方表并运行测试:
访问剩余的表,通过指定数字或Race统计结果。卡方检验的所有结果都会被保存,例如
Here is another approach. First set up the master table:
Now a function to create 2x2 tables from a row in
Tbl
:Finally create Chi Square tables and run the test:
Access the remaining tables, statistical results by specifying the number or Race. All of the results of the Chi Square Test are saved, e.g.