



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An example of hypothesis testing using gas price data from massachusetts in 1993. Testing the normality of two samples using a lilliefors test and visualizing the data with a normal probability plot. The document also compares the means of the two samples using z-test and t-test, and investigates the shift in prices with a notched box plot and wilcoxon rank sum test.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Statistics Toolbox
This example uses the gas price data in the file gas.mat. The file contains two random samples of prices for a gallon of gas around the state of Massachusetts in
A hypothesis test can be used to quantify the test of normality. Since each sample is relatively small, a Lilliefors test is recommended. lillietest(price1) ans = 0 lillietest(price2) ans = 0 The default significance level of lillietest is 5%. The logical 0 returned by each test indicates a failure to reject the null hypothesis that the samples are normally distributed. This failure may reflect normality in the population or it may reflect a lack of strong evidence against the null hypothesis due to the small sample size. Now compute the sample means: sample_means = mean(prices) sample_means = 115.1500 118. You might want to test the null hypothesis that the mean price across the state on the day of the January sample was $1.15. If you know that the standard deviation in prices across the state has historically, and consistently, been $0.04, then a z-test is appropriate. [h,pvalue,ci] = ztest(price1/100,1.15,0.04) h = 0 pvalue =
ci = 1.1340 1. The logical output h = 0 indicates a failure to reject the null hypothesis at the default significance level of 5%. This is a consequence of the high probability under the null hypothesis, indicated by the p-value, of observing a value as extreme or more extreme of the z-statistic computed from the sample. The 95% confidence interval on the mean [1.1340 1.1690] includes the hypothesized population mean of $1.15. Does the later sample offer stronger evidence for rejecting a null hypothesis of a state-wide average price of $1.15 in Febuary? The shift shown in the probability plot and the difference in the computed sample means suggest this. The shift might indicate a significant fluctuation in the market, raising questions about the
The plot displays the distribution of the samples around their medians. The heights of the notches in each box are computed so that the side-by-side boxes have nonoverlapping notches when their medians are different at a default 5% significance level. The computation is based on an assumption of normality in the data, but the comparison is reasonably robust for other distributions. The side-by-side plots provide a kind of visual hypothesis test, comparing medians rather than means. The plot above appears to barely reject the null hypothesis of equal medians. The nonparametric Wilcoxon rank sum test, implemented by the function ranksum, can be used to quantify the test of equal medians. It tests if two independent samples come from identical continuous (not necessarily normal) distributions with equal medians, against the alternative that they do not have equal medians. [p,h] = ranksum(price1, price2) p =
h = 1 The test rejects the null hypothesis of equal medians at the default 5% significance level. Hypothesis Test Assumptions Available Hypothesis Tests © 1984-2006 The MathWorks, Inc. • Terms of Use • Patents • Trademarks • Acknowledgments
© 1984-2006 The MathWorks, Inc. • Terms of Use • Patents • Trademarks • Acknowledgments