Permutation Method for Two-Way Tables

gender = c(rep("male",550),rep("female",427))
rushed = c(rep("always",304),rep("sometimes",513),rep("never",160))
randomTable=table(gender,sample(rushed))
mosaicplot(randomTable,color=T,las=1)

Try writing a short simulation of lots of random two-way tables, and for each one, compute its chi-squared test statistic using the command chisq.test(randomTable)$statistic. Store these results and make a histogram for the resulting distribution.

The actual results of the 2004 General Social Survey question are shown below.

actualTable = matrix(c(116,229,82,188,284,78),3,2)
colnames(actualTable)=c("male","female")
rownames(actualTable)=c("always","sometimes","never")

How extreme is the chi-square value for our actual table versus the many random tables we generated in our simulation?

How do the p-values of the simulation method compare with the chi-squared distribution p-value?