cs447 - Tool Using Simulation To Test A Hypothesis
cs447 - Tool Using Simulation To Test A Hypothesis
Use this tool as a general guide to testing hypotheses with a simulation-based approach in R.
Step 1: Specify null (H0) and alternative (HA) hypotheses. The H0 is the status quo, or what you would
expect based on your current understanding. The HA is a new discovery or finding.
Step 2: Construct a null distribution of the sample statistic. Do this by simulating many samples
under the assumption that the H0 is correct, and visualizing the distribution of sample statistics with
a histogram.
Step 3: Plot the observed sample statistic on the histogram and calculate the p-value. Both the
histogram and the p-value indicate the chance of seeing a sample statistic of the size you observed
in your sample if the H0 is correct.
Step 4: Use the cut-off value to make a decision. If the p-value is less than the cut-off value, reject
the H0 and select the HA. If the p-value is greater than the cut-off value select the H0.
New 52 27 25 51.9
Old 51 22 29 43.1
The observed sample statistic from these data is the percent success for the new treatment minus
the percent success of the old treatment, which is 8.8%. This sample statistic could indicate that the
new treatment is better than the old treatment, but we should check this by testing the uncertainty
around this result.
Step 1:
H0: The new treatment and the old treatment work equally well in the population.
HA: The new treatment works better than the old treatment in the population.
Step 2: Construct the null distribution that assumes both new and old treatments have the same
chance of success. Based on the table of results above, the total % success is 47.6%. Simulate many
samples and record the difference between the success rates of new and old treatments (sample
statistic) on each sample. Visualize this null distribution in a histogram using the code below:
# Calculate and store the sample statistic for this sample iteration:
p_diff = p_new_sim - p_old_sim
store_p_diff[i] = p_diff
Step 4: Make a decision. Here, we’ll use the standard cut-off value of p-value = 0.05, which keeps the
false positive rate at 5%. Based on our simulation, the p-value is 0.18 (18%), which is higher than the
cut-off value, so we are unable to reject the null hypothesis. Based on this result, we cannot reject
the null hypothesis, so our data do not indicate that the new treatment works better than the
old one.