I'm trying to create a simulation for a proportion test to see how often I would get a significant results (i.e. p/value < 0.05). I'm assuming unequal population sizes, so for example
test <- rbinom(100, 5000, 0.05)
ctrl <- rbinom(100, 10000, 0.04)
Here I have 100 simulated tests, with 5000 in the test population and 10000 in the control, and an actual difference in conversion rate (0.05 for test and 0.04 for control).
I now want to run a proportion test for each of these simulated tests and get the p value. So for the very first test I would do:
prop.test(c(test[1], ctrl[2]), c(5000, 10000))$p.value
and then I'm looping through this with a for loop to get the p value for each of the simulated tests.
I'm looking to do this in a more compact way. I found a way to do it for a 1-sample proportion test with Map here , but I'm stuck how to do it for a 2-sample test. It does seem like I should be able to do it in a single line, and just get a vector of p-values as the output.
I tried the following
Map(prop.test, c(test,ctrl), c(5000, 10000), alternative="two.sided", correct = F)
But it's giving me 200 1-sample proportion tests, in stead of 100 2-sample proportion tests...any ideas what I can do to fix it?
Ideally I woul get a vector of length 100 with p.values so I can just check what portion is under 5% and that would be the tests power..