# Chi-square test alternatives when cell expecteds condition violated: Bayesian method

Say I have data collected from an independent multinomial sampling scheme that violates Cochran's cell expecteds condition. Instead of Pearson's $\chi^2$ test of independence, can I use the Bayesian method?

If so, I would like to make sure that I am making the right interpretations. The raceDolls example in the BayesFactor package was useful, but I want to extend this to an nx5 table and make sure I understand the output. Here's an example:

set.seed(21)
#Create fake data. Yes, I could just create a table with those probabilities, but this was more fun.
df <- data.frame(subjectType = sample(LETTERS[1:5], 150, replace=TRUE, prob=c(0.15, 0.1, 0.09, 0.22, 0.44)))
df$probs <- ifelse(df$subjectType == "A", "c(0.05, 0, 0, 0.09, 0.86)",
ifelse(df$subjectType == "B", "c(0.2, 0, 0, 0.14, 0.66)", ifelse(df$subjectType == "C", "c(0, 0.23, 0, 0, 0.77)",
ifelse(df$subjectType == "D", "c(0.1, 0.15, 0.03, 0.09, 0.63)", ifelse(df$subjectType == "E", "c(0.24, 0.14, 0.02, 0.05, 0.55)",NA)))))
splitDf <- split(df, df$subjectType) splitDf <- lapply(splitDf, function(x) cbind(x, cat = eval(parse(text = paste("sample(LETTERS[22:26], nrow(x), replace=T, prob=", x$probs, ")")))))
df <- do.call("rbind", splitDf)
tabDf <- table(df$cat, df$subjectType)

#Tests
chisq.test(tabDf)
#fisher.test(tabDf) # common alternative. Assumes fixed totals
friedman.test(tabDf) # another test that's used as an alternative

library(BayesFactor)
contingencyTableBF(tabDf, sampleType = "indepMulti", fixedMargin = "cols")


The output shows $BF_{01}^I = 0.07$, so it 14 times more likely under the null hypothesis of independence than the alternative hypothesis.