MTB > # Solution for Exercise 27 STAT 657, Fall 2012 MTB > # I'll put the data into c1 and c2 and do some simple exploration. MTB > set c1 DATA> 1.18 1.42 0.69 0.88 1.62 DATA> 1.09 1.53 1.02 1.19 1.32 DATA> end MTB > set c2 DATA> 1.72 1.62 1.69 0.79 1.79 DATA> 0.77 1.44 1.29 1.96 0.99 DATA> end MTB > name c1 'First' c2 'Second' c3 'n score' c4 'combined' c5 'group' MTB > dotplot c1 c2; SUBC> same. . . . . .. . . . . -----+---------+---------+---------+---------+---------+-First .. . . . . .. . . -----+---------+---------+---------+---------+---------+-Second 0.75 1.00 1.25 1.50 1.75 2.00 MTB > desc c1 c2 N MEAN MEDIAN TRMEAN STDEV SEMEAN First 10 1.1940 1.1850 1.2038 0.2897 0.0916 Second 10 1.406 1.530 1.416 0.428 0.135 MIN MAX Q1 Q3 First 0.6900 1.6200 0.9850 1.4475 Second 0.770 1.960 0.940 1.737 MTB > nsco c1 c3 MTB > plot c3 c1 n score - * - - 1.0+ * - - * - * - * 0.0+ - * - * - * - -1.0+ * - - - * +---------+---------+---------+---------+---------+------First 0.60 0.80 1.00 1.20 1.40 1.60 MTB > nsco c2 c3 MTB > plot c3 c2 n score - * - - 1.0+ * - - * - * - * 0.0+ - * - * - * - -1.0+ * - - - * ----+---------+---------+---------+---------+---------+--Second 0.75 1.00 1.25 1.50 1.75 2.00 MTB > # I'll use Student's two-sample t test for the general two-sample problem. MTB > # Since the null hypothesis is that of identical distributions, if the MTB > # null hypothesis is true then Student's t test has wonderful robustness, MTB > # since if the distributions are identical and the sample sizes are the MTB > # same, the two sample means will have the same sampling distribution, and MTB > # the difference of the two sample means will have a sampling distribution MTB > # symmetric about 0. Since heavy tails make the t test conservative, and MTB > # light tails present little problem with two samples of size 10, there is MTB > # little danger that any nonnormality will lead to a falsely small p-value. MTB > # Heavy tails don't seem to be indicated. (Looking at the dotplots above, MTB > # it appears that if we combine the two samples (which would be appropriate MTB > # for getting an idea about the common distribution if the null hypothesis MTB > # is true), the 20 values appear close to uniformly spread over an interval, MTB > # suggesting a light-tailed distribution.) So, all in all, the t test MTB > # should be trustworthy (although it may not have the greatest power for MTB > # detecting distribution differences). MTB > twos c1 c2; SUBC> pool. TWOSAMPLE T FOR First VS Second N MEAN STDEV SE MEAN First 10 1.194 0.290 0.092 Second 10 1.406 0.428 0.14 95 PCT CI FOR MU First - MU Second: ( -0.556, 0.13) TTEST MU First = MU Second (VS NE): T= -1.30 P=0.21 DF= 18 POOLED STDEV = 0.366 ******************************************************************************* StatXact yields a p-value of 0.2112, which should be rounded to 0.21 due to the absence of exact normality. ******************************************************************************* MTB > # I'll try the M-W test. MTB > mann c1 c2 Mann-Whitney Confidence Interval and Test First N = 10 Median = 1.1850 Second N = 10 Median = 1.5300 Point estimate for ETA1-ETA2 is -0.2600 95.5 pct c.i. for ETA1-ETA2 is (-0.5999,0.1900) W = 87.5 Test of ETA1 = ETA2 vs. ETA1 n.e. ETA2 is significant at 0.1988 The test is significant at 0.1986 (adjusted for ties) Cannot reject at alpha = 0.05 *************************************************************************** Using StatXact, an exact p-value of 0.197 is obtained. Minitab's approx. p-value (based on normal approx. w/ c.c.) of about 0.199 is pretty close to the exact value. StatXact's approximate p-value (based on normal approx. w/o c.c.) of about 0.186 isn't as good. Just for fun, I tried using a c.c. of 1/4 instead of 1/2, since using the midranks, the possible values of the test statistic are no longer just inte- gers, but rather they are separated by increments of 1/2, and so half the distance between two consecutive values is 1/4. This resulted in an approx. p-value of about 0.192 (which isn't as close to the exact value as is the approximate p-value based on the usual 1/2 c.c.). *************************************************************************** MTB > # I'll try an approximate version of the two-sample median test (not MTB > # using Yates's continuity correction). MTB > stack c1 c2 c4; SUBC> subs c5. MTB > mood c4 c5 Mood median test of combined Chisquare = 0.80 df = 1 p = 0.371 Individual 95.0% CI's group N<= N> Median Q3-Q1 ----+---------+---------+---------+-- 1 6 4 1.185 0.462 (-------+----------) 2 4 6 1.530 0.797 (-----------------------+--------) ----+---------+---------+---------+-- 1.00 1.25 1.50 1.75 Overall median = 1.305 A 95.0% C.I. for median(1) - median(2): (-0.700,0.430) MTB > # Since the only outcome less extreme than the observed one is MTB > # lower upper MTB > # First 5 5 MTB > # Second 5 5 MTB > # to get an exact p-value we only have to subtract the probability MTB > # associated with this one less extreme outcome from 1. Doing this, MTB > # one obtains an exact p-value of about 0.656. Just for fun, below MTB > # I'll compute an approximate p-value using the chi-square approximation MTB > # incorporating Yates's continuity correction. MTB > let k1 = 20*(36 - 16 - 10)*(36 - 16 - 10)/(10*10*10*10) MTB > cdf k1 k2; SUBC> chis 1. MTB > let k2 = 1 - k2 MTB > name k1 'teststat' k2 'p-value' c11 'sorted 1' c12 'sorted 2' MTB > print k1 k2 teststat 0.200000 p-value 0.654721 MTB > # It can be seen that using Yates's correction makes the approximate MTB > # p-value (0.655) pretty darn close to the exact p-value (0.656), MTB > # whereas not using Yates's correction led to a much different MTB > # approximate p-value (0.371). *************************************************************************** Using StatXact I obtained an exact p-value of 0.6563 (in agreement with the exact result reported above). *************************************************************************** MTB > # Now I'll try the W-W runs test. MTB > sort c1 c11 MTB > sort c2 c12 MTB > print c11 c12 ROW sorted 1 sorted 2 1 0.69 0.77 2 0.88 0.79 3 1.02 0.99 4 1.09 1.29 5 1.18 1.44 6 1.19 1.62 7 1.32 1.69 8 1.42 1.72 9 1.53 1.79 10 1.62 1.96 MTB > # There are only two tied values, a 1.62 in sample 1 and a 1.62 in MTB > # sample 2. If the 1.62 from sample 1 is put before the 1.62 from MTB > # sample 2 there are only 10 runs, but if the 1.62 from sample 2 is MTB > # put first there are 12 runs. Using Table D of G&C, it can be MTB > # that the probability of 10 or fewer runs is 0.414, and it can be MTB > # determined that the probability of 12 or fewer runs is 0.758 (if MTB > # you use a corrected version of the portion of Table D on p. 572). MTB > # Breaking the tie in a conservative manner means that we should MTB > # use 12 runs and report a p-value of 0.758. *************************************************************************** Using StatXact one gets the two exact p-values indicated above. The larger of the two, 0.758, should be used (given the instructions of the homework exercise). (Note: For 10 runs, StatXact's asymptotic p-value is done using the normal aproximation with a continuity correction, but for 12 runs some- thing is being done incorrectly ... it appears that the continuity correct- ion is applied wrong.) *************************************************************************** *************************************************************************** For the K-S test, StatXact produces an exact p-value of 0.4175. *************************************************************************** MTB > write 'Bearings' c1 c2 Writing data to file: Bearings.DAT MTB > save 'Bearings' Saving worksheet in file: Bearings.MTW