Congratulations! You now know how to implement a one-sample t-test in Python and verify the assumptions of the test. To recap, here are some of the things you learned:
- One-sample t-tests are used for comparing a sample mean to an expected population mean
- A one-sample t-test can be implemented in Python using the SciPy
- Assumptions of a one-sample t-test include:
- The sample was randomly drawn from the population of interest
- The observations in the sample are independent
- The sample size is large “enough” or the sample data is normally distributed
As a final exercise, some data has been loaded for you with purchase prices for consecutive days at BuyPie. You can access the first day using
daily_prices, the second using
daily_prices, etc.. To practice running a one-sample t-test and inspecting the resulting p-value, try the following:
Calculate and print out a p-value for day 1 where the null hypothesis is that the average purchase price was 1000 Rupees and the alternative hypothesis is that the average purchase price was not 1000 Rupees. Print out the p-value.
Run the same hypothesis tests for days 1-10 (the fastest way to do this is with a for-loop!) and print out the resulting p-values. What’s the smallest p-value you observe for those 10 days?
Try changing the null hypothesis so that the expected population mean that you’re testing against is different from 1000. Try any numbers that you want. How do your p-values change?
Solution code can be found in solution.py