Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Luis A. Afonso
Posts:
4,725
From:
LIsbon (Portugal)
Registered:
2/16/05


Testing differences on a normal sample pair
Posted:
Nov 5, 2012 1:08 PM


Testing differences on a normal sample pair
We intent this time to show how the Pvalues 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+n2) * (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+1002= 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 Discussion
Pvalues 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 AZ 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 = t REM 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 k 10 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



