0

I should choose and use right statistical testing between the variable “linolenic being greater than 0.33” and the variable “region being equal to Sardinia”. These are two binary variables, so I'm trying to use fisher.test, but how these could be changed into logical variables for table?

library(dslabs)
dt <- as.data.table(olive)
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
stack mek
  • 15
  • 5
  • Note that Fisher's "exact" test is not very accurate: https://www.zotero.org/groups/2199991/feh/tags/fishers-exact-test/library – Frank Harrell Apr 03 '21 at 12:05

1 Answers1

1

Is this what you're looking for?

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

And then conveniently:

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 
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57