简体   繁体   English

如何在 sas 中创建 2x2 表以进行 Fisher 精确测试

[英]How to create 2x2 table in sas for fisher exact test

I just performed the fisher test in R and in Excel on a 2x2 table with the contents 1 6 and 7 2. I can't manage to do this in sas.我刚刚在 R 和 Excel 中在内容为 1 6 和 7 2 的 2x2 表上执行了 Fisher 测试。我无法在 sas 中执行此操作。

data my_table;
input  var1 var2 @@;
datalines;
1 6 7 2
;

proc freq data=my_table;
tables var1*var2 / fisher;
run;

The test somehow ignores that the table consists of the 4 variables but when I print the table it looks fine.该测试以某种方式忽略了该表由 4 个变量组成,但是当我打印该表时它看起来很好。 In the test the contents of the table are 0, 1, 1, 0. I guess I need to change something when creating the data but what?在测试中,表的内容是 0、1、1、0。我想我需要在创建数据时更改一些内容,但是什么?

You do NOT have two variables that each have two categories.您没有两个变量,每个变量都有两个类别。

Read the data in this way instead.改为以这种方式读取数据。

data have ;
  do var1=1,2 ; do var2=1,2;
    input count @@;
    output;
  end; end;
datalines;
1 6 7 2
;

Now VAR1 and VAR2 both have two possible values and COUNT has the number of cases for the particular combination.现在 VAR1 和 VAR2 都有两个可能的值,COUNT 有特定组合的案例数。 Use the WEIGHT statement to tell PROC FREQ to use COUNT as the number of cases.使用 WEIGHT 语句告诉 PROC FREQ 使用 COUNT 作为案例数。

proc freq data=have ;
  weight count ;
  tables var1*var2 / fisher ;
run;

在此处输入图像描述 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM