```Date: Nov 5, 2012 1:08 PM
Author: Luis A. Afonso
Subject: Testing differences on a normal sample pair

Testing differences on a normal sample pairWe intent this time to show how the P-values are distributed when one tests the difference of mean normal Populations. To this purpose samples X~N (0, 1).n and Y~N (0, 1): n are simulated and the statistics is: T = (xhat ? yhat - D)/s__s^2 = (ssdX +  ssdY)/(n+n-2) * (1/nX + 1/nY)ItÂ´s known that T follows a Student T with nX + nY - 2 df. Lacking an algorithm to provide the inverse T we switched to normal which is sufficiently accurate since the sample sizes are large, n=100, because student t with 100+100-2= 198 df is very lose to normal standard. See 26.2.10 M. Abramowitz, I. Stegun, Handbook of Mathematical Functions. A recurrence formula (program WATCH) my own, was used.Results and DiscussionP-values are shown (not in full) distributed in classes each one 0.05 amplitude. One get only 2% *rejections* from [0, 1], and any (as expected) when D= 0. We counted 1- alpha(D= -0.5)  = 37982/40000 = 0.950, 1- alpha(D=  0.5)  = 37903/40000 = 0.948  very close to 0.95, as it was demanded.X=N(0,1):100	Y=N(0,1):100 __________D= -0.5___D=0_____D= 0.5____0________________1912_____37903____1________________1804_______716____2________________2008_______228____3________________1978_______120____4________________1892________58____5________________1981________33____6________________2050_______7________________2113_______8________________2091_______9________________2023______10________________2084______11________________2104______12________________1974______13________________1992______14________34______2025______15________64______1977______16_______131______1858______17_______240______2017______18_______699______2108______19_____37982______3009_____Total____39209_____40000______39175_____>1:     791_____________<0 :    825   ( my first trial: May 30, 2010 12:32 AM)Luis A. Afonso          REM "WATCH"        CLS        DEFDBL A-Z        PRINT : PRINT : PRINT "___WATCH____"        INPUT " Two N(0,1) samples , size  "; size        INPUT "                       D=   "; mu        INPUT "        How many            "; repeat        pi = 4 * ATN(1): cx = 1 / SQR(2 * pi)        DIM kk(20)        DEF fng (x, k) = -.5 * x ^ 2 * (2 * k + 1) / ((k + 1) * (2 * k + 3))        FOR j = 1 TO repeat: RANDOMIZE TIMER        LOCATE 5, 50        PRINT USING "#########"; repeat - j       PRINT : PRINT       m1 = 0: m2 = 0: ss1 = 0: ss2 = 0       FOR i = 1 TO size: r1 = RND: r2 = RND       aa = SQR(-2 * LOG(r1))       x = aa * COS(2 * pi * r2)       y = aa * SIN(2 * pi * r2)       m1 = m1 + x / size: ss1 = ss1 + x * x       m2 = m2 + y / size: ss2 = ss2 + y * y       NEXT i       ssd1 = ss1 - size * m1 * m1       ssd2 = ss2 - size * m2 * m2       sz = 1 / size + 1 / size       t = (m1 - m2) / SQR((ssd1 + ssd2) / (size + size - 2) * sz)       x = tREM       x = (m1 - m2 - mu) / SQR(2 / size)REM    ___  x^-1___      zu = ABS(x): s = cx * zu: ante = cx * zu      FOR k = 0 TO 7777777      xx = ante * fng(zu, k)      s = s + xx      IF ABS(xx) < .0000005 THEN GOTO 10      ante = xx      NEXT k10    REM      IF x < 0 THEN np = .5 - s      IF x >= 0 THEN np = .5 + s      IF np < 0 THEN lft = lft + 1      IF np > 1 THEN rgt = rgt + 1      REM       by classes      FOR c = 0 TO 19      t0 = c / 20: t1 = (c + 1) / 20      IF np > t0 AND np < t1 THEN kk(c) = kk(c) + 1      NEXT c      PRINT "______________wait please "      NEXT j      FOR y = 0 TO 19: sum = sum + kk(y)      PRINT USING " ###)  ######       "; y; kk(y);      NEXT y      PRINT sum      PRINT USING " ###### "; lft; rgt      END
```