rpruim/mosaic — Issue #45: Make resampling for 2 proportions simpler
Author: rpruim
Created: 2012-02-29 22:37:15+00:00
State: open

On Wed, Feb 29, 2012 at 1:10 PM, Nicholas Horton wrote:
I'm trying to demonstrate to someone from a K-12 perspective how to undertake a permutation test of a difference in proportions for a 2x2 table using mosaic.

This is more of a PITA than it needs to be unless you can roll your own diffprop() function or similar. Unfortunately, neither chisq.test() nor t.test() (for the analogous problem relating to the difference in means) gives you what you need.

To give you an example of how convoluted this was when we last considered this issue, here's what we ended up with in the workshop notes (for the 2 group comparison of continuous variables):

```R
simulations <- 500
test.stat <- abs(diff(aggregate(cesd ~ sex, data=HELP, mean)$cesd))
test.stat
rtest.stats <- do(simulations) * c(diff= diff(aggregate(cesd ~ shuffle(sex), HELP, mean)$cesd))
histogram(~ abs(diff), rtest.stats, n=40, xlim=c(0, 6),
groups=abs(rtest.stats$diff) >= test.stat, pch=16, cex=.8 ) # was dotPlot
ladd(panel.abline(v=test.stat))
```
Yuck.

Any thoughts or suggestions about how to do this would be greatly appreciated.

Nick