Skip to main content

Section 16.9 Technology Detour – Simulating Random Assignment (two-way tables)

Simulation Steps.

Step 1: Simulate a random sample (number of successes for group 1) using the hypergeometric distribution
Step 2: Calculate the number of successes for group 2 (total successes – number of successes group 1)
Step 3: Convert the counts to proportions
Step 4: Calculate the difference in proportions, relative risk etc.
Keep in mind you can use "log" to calculate the natural logs of values. Also recall how you created a Boolean expression in Investigation 3.1 to find the p-value from the simulated results.
In R:
Hint. Random assignment simulation in R
Use the rhyper function to simulate random assignment:
VacInfCount = rhyper(10000, 210, 4985, 2584)
# 210 is the number of successes (M)
# 4985 is the number of failures (N - M)
# 2584 is the sample size (n)

UnvacInfCount = 210 - VacInfCount
Unvacphat = UnvacInfCount/2584
In JMP:
Hint. Random assignment simulation in JMP
For Investigation 3.8:
  • Open the CPRvCC.jmp file. The first column is the response variable (survived to discharge from hospital or not) and the second column is the explanatory variable.
  • You will notice an element called Randomization Test in the top left corner. Click on the pull-down menu and select Run Script.
  • Close the new windows (don’t save changes). Now use the pull down menu on the script item and select Edit. The lines preceded by "//" are comments. Uncomment the resultCloseWindow command, change the "wait" from one to zero, and the number of trials from 1 to 100. Press Run.
  • If you comment out the "wait" line you can run many more trials.
At the end you will have the results for 100 hypothetical studies where the rows and columns are fixed and we store how many survivors end up in the CPR group. You can calculate the number of successes in the CC group using 64 – count.
You have attempted of activities on this page.