Simple statistics Hypothesis testing for the difference in means of two samples. Syntax [h,significance,ci] = ttest2(x,y) [h,significance,ci] = ttest2(x,y,alpha) [h,significance,ci] = ttest2(x,y,alpha,tail) Description h = ttest2(x,y) performs a t-test to determine whether two samples from a normal distribution (in x and y) could have the same mean when the standard deviations are unknown but assumed equal. h, the result, is 1 if you can reject the null hypothesis at the 0.05 significance level alpha and 0 otherwise. significance is the p-value associated with the T-statistic. significance is the probability that the observed value of T could be as large or larger under the null hypothesis that the mean of x is equal to the mean of y. ci is a 95% confidence interval for the true difference in means. [h,significance,ci] = ttest2(x,y,alpha) gives control of the significance level, alpha. For example if alpha = 0.01, and the result, h, is 1, you can reject the null hypothesis at the significance level 0.01. ci in this case is a 100(1-alpha)% confidence interval for the true difference in means. ttest2(x,y,alpha,tail) allows specification of one or two-tailed tests. tail is a flag that specifies one of three alternative hypotheses:  tail = 0 (default) specifies the alternative, .  tail = 1 specifies the alternative, .  tail = -1 specifies the alternative, . Examples This example generates 100 normal random numbers with theoretical mean zero and standard deviation one. We then generate 100 more normal random numbers with
“broken” and they are, in fact “ok” we will allow data to be recorded and acted on that is in fact “erroreous”. This problem is similar to flipping a coin, that is, there should be a 50% probability of seeing the “A” or “B” higher. Thus we can express this situation in terms of flipping coins (since we can more easily visualize that). Just how surprising is it to see 15 “heads” when we expect p*n=10 What is the probability of seeing 15 heads? What is the probability of seeing at least 15 heads? Notice that what would surprise us is not seeing 15 H’s but seeing as 15 or more heads. If you were applying for a job and you were expecting a starting salary of around $55,000 and you were offered $42,000 or $88,888 are you surprised because of the “specific” (exact) number or the “size” of the number (range of values)? Therefore, we aren’t interested in P(x=15) = BINOMDIST(15,20,0.5,FALSE) = 0.014785767 but rather P(x>=15) = 1 – P(x<14) = 1-BINOMDIST(14,20,0.5,TRUE) = 0.020694733 Thus, we are rather surprised to see 15 or more H’s (or A’s>B’s) because by chance we should only see this happening 2% of the time. Thus, because we DID see it happen, we will believe we are seeing something “real” because it happens less often than the 5% of the time it will happen by chance. In words, suppose someone has just flipped a “claimed” fair coin 20 times and they got 19 heads. Do you think you just witnessed a once-in-a-lifetime occurrence that happened by random chance or do you think this is evidence that the coin is not fair and you aren’t seeing anything particularly rare at all? heads p(x>=H) 0 1.00000 1 1.00000 2 0.99998 3 0.99980 4 0.99871
Sample Mean is = 85 Sample SD is = 10 Sample Size is = 10 Calculations t-statistic -1.58113883 0.148304704 Decision FTR Null Wording 2: At a 95% CL I accept that the machine is working properly. (That is, no one to “fix it”). One Tailed Examples We have readjusted our machine to produce bags labeled “contains 95g”. We have sampled 10 bags and find xbar=92.0g with sd=5g. Is the machine putting in at least 95g? Use 95% CL. This is a one-tail case since we are interested in “putting in at least 95” vs “not putting in at least 95” (that is, putting in less than 95). One-Tailed (Right Tail) Hypotheses Ho: μ <= 95 H1: μ > 95
Two-Tailed Test (u=uo) Hypotheses Ho: μ1-μ2 = 0 H1: μ1-μ2 <> 0 α = 0.1 Sample Evidence Sample 1 Sample 2 Sample Mean 5.7400 3.8750 Sample SD 2.3972 1.8557 Sample Size 10 10 Calculations t-statistic 1.9454069 p-value 0.0695135 Decision Reject Null CI Lower Bound CI Upper Bound 3.8972861