I've been investigating exact tests and during that I find monte carlo method very useful.
I can write my own code for randomization and permutation tests but I cannot figure out how R function chisq.test do the randomization.
I see chisq.test uses stats:::C_chisq_sim to do it. But no matter how I try to randomize numbers myself, I cannot get the logic straight.
Anyone can explain a little to me?
Let's say we have a table
1 5 | 6
3 3 | 6
-----+---
4 8 | 12
What numbers (col sums? total sum?) do we fix and what do we randomize?
Thanks.