R 中的统计测试:fisher 测试和二元逻辑变量

Statistical testing in R: fisher test and logical variables as binary

我应该在变量“亚麻酸大于 0.33”和变量“区域等于撒丁岛”之间选择和使用正确的统计检验。这是两个二进制变量,所以我正在尝试使用 fisher.test,但是如何将它们更改为 table 的逻辑变量?

library(dslabs)
dt <- as.data.table(olive)

这是您要找的吗?

table(dt[,.(Region = region == "Sardinia", Linolelic = linolenic > 0.33)])
#       Linolelic
#Region  FALSE TRUE
#  FALSE   220  254
#  TRUE     86   12

然后顺手:

fisher.test(table(dt[,.(Region = region == "Sardinia", Linolelic = linolenic > 0.33)]))
#   Fisher's Exact Test for Count Data
#
#data:  table(dt[, .(Region = region == "Sardinia", Linolelic = linolenic > 0.33)])
#p-value = 4.58e-15
#alternative hypothesis: true odds ratio is not equal to 1
#95 percent confidence interval:
# 0.05870264 0.23036344
#sample estimates:
#odds ratio 
# 0.1212736