如何对这组数据(标称变量)应用fisher检验

如何对这组数据(标称变量)应用fisher检验,r,testing,statistics,R,Testing,Statistics,我对统计学相当陌生: fisher = function(idxToTest, idxATI){ idxDependent=c() dependent=c() p = c() for(i in c(1:length(idxToTest))) { tbl = table(data[[idxToTest[i]]], data[[idxATI]]) rez = fisher.test(tbl, workspace = 20000000000) if(rez$p.value&

我对统计学相当陌生:

fisher = function(idxToTest, idxATI){

idxDependent=c()
dependent=c()
p = c()

for(i in c(1:length(idxToTest)))
{
    tbl = table(data[[idxToTest[i]]], data[[idxATI]])
    rez = fisher.test(tbl, workspace = 20000000000)
    if(rez$p.value<0.1){
        dependent=c(dependent, TRUE)
        if(rez$p.value<0.1){
            idxDependent = c(idxDependent, idxToTest[i])
        }
    }
    else{
        dependent = c(dependent, FALSE)
    }
    p = c(p, rez$p.value)
}

}
我的数据来自CSV:

data = read.csv('***.csv', header = TRUE, sep=',');
我的第一个问题是,我不知道如何从以下方面交谈:

Loan.Purpose   Home.Ownership
lp_value_1     ho_value_2
lp_value_1     ho_value_2
lp_value_2     ho_value_1
lp_value_3     ho_value_2
lp_value_2     ho_value_3
lp_value_4     ho_value_2
lp_value_3     ho_value_3
致:

第二个问题是我不知道第二个参数应该是什么

更新后:这是我使用fisher.test(myTable)得到的结果。:

其中
myTable
为:

           MORTGAGE NONE OTHER OWN RENT
  car                      18    0     0   5   27
  credit_card             190    0     2  38  214
  debt_consolidation      620    0     2  87  598
  educational               5    0     0   3    7
  ...

基本上,fisher测试只适用于较小的数据集,因为它们需要大量内存。但这一切都是好的,因为卡方检验只需要很少的额外假设,而且在计算机上更容易实现。只要做:

chisq.test(Loan.Purpose,Home.Ownership)
获取你的p值

确保您通读并理解chisq.test的帮助页面,尤其是底部的示例

然后查看马赛克图,查看如下数量:

 mosaicplot(Loan.Purpose,Home.Ownership)
本参考资料解释了马赛克图的工作原理


您是否尝试过
表格(贷款、用途、房屋、所有权)
?为什么不使用
fisher.test()
?@Seth-好了,现在表格行似乎正常了,我在打印时获得了正确的表格数据,但出现了一个新错误。检查更新后我不确定该函数是如何工作的,但您可以将该表转换为,例如,如果该函数期望的是
as.matrix(您的表)
,则可以将其转换为矩阵。您的内存不足,无法运行准确的测试。您是否考虑过
chisq.test()
           MORTGAGE NONE OTHER OWN RENT
  car                      18    0     0   5   27
  credit_card             190    0     2  38  214
  debt_consolidation      620    0     2  87  598
  educational               5    0     0   3    7
  ...
chisq.test(Loan.Purpose,Home.Ownership)
 mosaicplot(Loan.Purpose,Home.Ownership)