________________________________________ From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of bbbnc [benwo...@gmail.com] Sent: Wednesday, February 25, 2009 6:01 AM To: r-help@r-project.org Subject: [R] Simulating contingency table (Basic question, help please)
I'd like to carry out a Monte Carlo simulation test where given data is a contingency table. I think this is something to do with using rmultinonom(), but I'm not sure how to code this, to simulate contingency tables. Could anyone please help with how to use R to simulate contingency tables like this? Let m be your matrix (contingency table). Do something like: > p <- (rowSums(m)%o%colSums(m))/(sum(m)^2) > X <- rmultinom(2000,sum(m),p) and then > simstat <- > apply(X,2,function(x,k){chisq.test(matrix(x,nrow=k))$statistic},k=nrow(m)) will give you simulated chi-squared statistics. If you want some other statistic then obviously you need to modify the function which is applied to the columns of X. Note that the simulation is done under the usual contingency table null hypothesis of independence or homogeneity. If you have something else in mind you'll need to modify accordingly. cheers, Rolf Turner ###################################################################### Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ###################################################################### ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.