Repeating
- From: "\"Luis A. Afonso\"" <licas_@xxxxxxxxxxx>
- Date: Thu, 02 Nov 2006 06:43:33 EST
If we wish to test from two independent Populations X, Y
____H0: p1<=p2___against____H1: p1>p2
we can use one of the two procesdures:
A) Monte Carlo
____ R1 = number of successes observed, x , divided by the number of trials, nX,
____ R2 = y/nY
To obtain a pair of samples we use the random numbers: every time that RND<=R1 we count a success (and we repeat nX times, total of successes = x); every time that RND<=R2 occurs one success for the sample 2 is counted, total of successes, y.
Two things could happen
___or x/nX <=y/nY and I count 1 for H0
___or x/nX > y/nY not.
The frequency of the first event above (out of a many large number of pairs, for example 50000) is approximately the probability relative to H0.
This is an exact algorithm but having random errors (RNG).
Example:
Observed 1 out 10, 15 out 30:
__x/N1 =1/10__y/N2 = 15/30___H0: p1<=p2
prob. 0.9952
(Note: Using the Normal approximation - not pooled mean – we found Z=3.0382, p=0.9988)
B) the EXACT method
I was described yet. For this example p=0.9976.
Programs
Respectively *pnpn* and *pxact*
REM "pnpn"
CLS : PRINT " pnpn "
DEFDBL A-Z
PRINT " H0: p1<=p2 "
INPUT " p1 = "; p1
INPUT " n1= "; n1
INPUT " p2 "; p2
INPUT " n2= "; n2
INPUT " all = "; all
s2 = p1 * (1 - p1) / n1 + p2 * (1 - p2) / n2
s = SQR(s2): znp = (p2 - p1) / s
FOR i = 1 TO all
RANDOMIZE TIMER
LOCATE 10, 50
PRINT USING "########"; all - i
x = 0: y = 0
FOR j = 1 TO n1
IF RND <= p1 THEN x = x + 1
NEXT j
FOR k = 1 TO n2
IF RND <= p2 THEN y = y + 1
NEXT k
d = y / n2 - x / n1
IF d > 0 THEN yes = yes + 1 / all
NEXT i
PRINT USING
" p(H0:p1<=p2, Ha:p2<p1)= #.####"; yes
a$ = " fail to reject H0 "
b$ = " reject H0 "
IF yes <= cl THEN PRINT a$
IF yes >= cl THEN PRINT b$
x = znp
IF x > 6 THEN GOTO 123
pi = 4 * ATN(1): c = 1 / SQR(2 * pi)
IF x <= 0 OR x > 6 THEN GOTO 125
DEF fng (x, j) = -x ^ 2 * (2 * j + 1) /
((j + 1) * (2 * j + 3)) * .5
s = c * x: antes = c * x
FOR j = 0 TO 500
xx = antes * fng(x, j)
s = s + xx: antes = xx
IF ABS(xx) < 5E-10 THEN GOTO 100
NEXT j
100 COLOR 3
PRINT : PRINT : PRINT
PRINT USING " Znp = ##.#### "; znp;
PRINT " p(<=Znp) ";
: PRINT USING "###.#### "; .5 + s
GOTO 125
123 PRINT " Z>6 "
125 COLOR 7: END
REM "pxact"
CLS
DEFDBL A-Z
INPUT " X : p= "; pX
INPUT " n= "; nX
INPUT " Y : p= "; pY
INPUT " n= "; nY
DIM x(nX), y(nY)
x(0) = (1 - pX) ^ nX: y(0) = (1 - pY) ^ nY
FOR i = 0 TO nX - 1
x(i + 1) = x(i) * (nX - i) / (i + 1) * pX / (1 - pX)
NEXT i
FOR j = 0 TO nY - 1
y(j + 1) = y(j) * (nY - j) / (j + 1) * pY / (1 - pY)
NEXT j
FOR i1 = 0 TO nX: FOR i2 = 0 TO nY
d = ABS(i1 / nX - i2 / nY)
IF d > 0 THEN f = f + x(i1) * y(i2)
dd = i1 / nX - i2 / nY
IF dd > 0 THEN ff = ff + x(i1) * y(i2)
IF dd <= 0 THEN fff = fff + x(i1) * y(i2)
NEXT i2
NEXT i1
PRINT USING
" p[ |X/nX-Y/nY|>0 ]= #.#### "; f
PRINT USING
" p[ X/nX-Y/nY >0 ]= #.#### "; ff
PRINT USING "
p[ X/nX-Y/nY <=0 ]= #.#### "; fff
END
_____licas (Luis A. Afonso)
.
- Follow-Ups:
- Re: Repeating
- From: Jack Tomsky
- Re: Repeating
- From: Reef Fish
- Re: Repeating
- References:
- The *team* of imbeciles try to elude the EXACT method worth
- From: \"Luis A. Afonso\"
- The *team* of imbeciles try to elude the EXACT method worth
- Prev by Date: Re: The *team* of imbeciles try to elude the EXACT method worth
- Next by Date: Re: Anyone found an Elementary Bayesian Book yet?
- Previous by thread: Re: The *team* of imbeciles try to elude the EXACT method worth
- Next by thread: Re: Repeating
- Index(es):
Relevant Pages
|