I am trying to find out of there is association between nominal variables. The response variable has three levels, and the predictors have also at least tree levels. Some of the group have very little data and according to my research the Fisher's exact test is appropriate in such cases.
Below some example data:
y <- floor(runif(30, min=0, max=3))
x1 <- floor(runif(30, min=0, max=7))
x2 <- floor(runif(30, min=0, max=5))
x3 <- floor(runif(30, min=0, max=5))
x4 <- floor(runif(30, min=0, max=7))
testDt <- cbind(y, x1, x2, x3, x4)
testDt <- as.data.table(testDt)
factorVars <- c("y", "x1", "x2", "x3", "x4")
testDt <- testDt[,(factorVars):=lapply(.SD, haven::as_factor),.SDcols=factorVars]
i was also able to run the Fisher's Exact Test:
> fisher.test(table(as.factor(testDt$y), as.factor(testDt$x1)), workspace = 2e8, simulate.p.value=TRUE)
Fisher's Exact Test for Count Data with simulated p-value (based on 2000 replicates)
data: table(as.factor(testDt$y), as.factor(testDt$x1))
p-value = 0.7941
alternative hypothesis: two.sided
For the sake of the question, imagine this was significant. Now i want to do the Ah-hoc pairwise comparisons, but i cannot seem to make it work. I have tried using the function pairwise_fisher_test
as in this example. I also tried using pairwiseNominalIndependence
as outlined here. However, i always keep getting some errors.
Any ideas how i can use these ad-hoc pairwise comparison functions? Or an alternative function what does pairwise comparison for data with low expected cell values?