I am starting from this contingency table:
mat <- matrix(c(58, 60, 29, 190, 87, 22, 167, 53, 123, 79, 80, 36, 2, 65, 24, 312, 131, 39, 178, 85, 37, 151, 129, 27, 0, 10, 14, 104, 87, 60, 106, 78, 34, 165, 68, 10, 0, 0, 0, 12, 44, 11, 48, 0, 2, 0, 0, 0, 55, 6, 7, 15, 11, 2, 179, 7, 1, 6, 0, 0, 1, 7, 13, 37, 62, 29, 29, 24, 16, 59, 58, 40, 82, 9, 17, 7, 0, 0), nrow = 6)
rownames(mat) <- c("Cinque", "Quattro", "Tre", "Due", "Uno", "Sei")
colnames(mat) <- c("rovere", "castagno", "cerro", "faggio", "leccio", "ostrya", "sughera", "larice", "abete", "peccio", "pinomed", "pinonero", "silvestre")
I need to know if the distribution I am observing in my contingency table (pairwise) is casual or not. I would need to go through these steps:
- Shuffle the values in the table.
For this part I am using this code:
require(picante)
out <- randomizeMatrix(mat, null.model = c("richness"),
iterations = 1000)
- Calculate a chi2 value for each cell in the randomized table
- Replicate the process 10000 times (I thought I could use a loop for this part) and visualize the chi2 results distribution for each cell
- Verify where the chi2 I get from the original table for each cell is placed in the aforementioned distribution.
I am not really practical in R, so I am not sure how to achieve this (the chisq.test() function only works on the table as a whole). Any ideas?
Thank you!