In the last exercise, we inspected a sample of 50 purchase prices at BuyPie and saw that the average was 980 Rupees. Suppose that we want to run a one-sample t-test with the following null and alternative hypotheses:
- Null: The average cost of a BuyPie order is 1000 Rupees
- Alternative: The average cost of a BuyPie order is not 1000 Rupees.
SciPy has a function called
ttest_1samp(), which performs a one-sample t-test for you.
ttest_1samp() requires two inputs, a sample distribution (eg. the list of the 50 observed purchase prices) and a mean to test against (eg.
tstat, pval = ttest_1samp(sample_distribution, expected_mean)
The function uses your sample distribution to determine the sample size and estimate the amount of variation in the population — which are used to estimate the null distribution. It returns two outputs: the t-statistic (which we won’t cover in this course), and the p-value.
ttest_1samp() to run the hypothesis test described above (null: the average price is 1000 Rupees; alternative: the average price is not 1000 Rupees).
Store the p-value in a variable called
pval. Remember that it is the second output of the
ttest_1samp() function. We won’t use the first output, the t-statistic, so you can store it in a variable with whatever name you’d like.
pval to the console.
Does the p-value you got make sense, knowing the mean of
prices and having inspected the data? (Look at the hint for an answer to this question).