Learn

So far, we’ve conducted a simulated binomial hypothesis test for Live-it-LIVE.com. In this exercise, we’ll use our code from the previous exercises to write our own binomial test function. Our function will use simulation, so it will estimate (albeit fairly accurately) the same p-values we would get using much more complex mathematical equations.

A function has been outlined for you in script.py which contains the code that we used for Live_it_LIVE inside a function named `simulation_binomial_test()`. Your goal in the next few exercises will be to edit this function so that it takes in any values for the following:

• The observed sample statistic (eg., 41 purchases)
• The sample size (eg., 500 visitors)
• The null probability of success (eg., 0.10 probability of a purchase)

The function should return a p-value for a one-sided test where the alternative hypothesis is that the true probability of success is LESS THAN the null.

### Instructions

1.

The `simulation_binomial_test()` function has been outlined for you in script.py. Add the following parameters to the function (in this order):

• `observed_successes` (the observed sample statistic, eg., 41 purchases)
• `n` (the sample size, eg., 500 visitors)
• `p` (the null probability of success, eg., 0.10)
2.

Next, edit the `simulation_binomial_test()` function to remove all of the hard-coded values (eg., 500, 0.1, 0.9, and 41) so that the proper parameters are used in each calculation.

3.

Uncomment the code at the bottom of script.py to test out your function and compare the results to the SciPy `binom_test()` function. Do you get similar answers?