Re: Monte Carlo: random simulation of events



MC-3 Testing differences on PROPORTIONS


__EXEMPLE #3

Suppose I want to test
_____H0: p1<=p2_____H1: p1>p2

when I draw a random sample (n1=50) with p1=0.5 from the Population 1 and another sample (n2=50), p2=0.1 from the Population 2.
The ABSOLUTE EXACT TEST is the following

___p(H0 true) = p(x<=y*n1/n2)

which is the sum of p(x)*p(y), from y=0 to y=n2, for all x such that x>=INT(y*n1/n2).

Result:

____p(H0 not rejected) = 0.9784642773435

No pooled variance
Only as comparison test Z gave Z0=1.92897 and with the Normal Approximation p(Z<Z0) = 0.973132706669889.

______licas (Luis A. Afonso)

REM "FORx"
CLS
DEFDBL A-Z
PRINT " p(x<=y*n1/n2) "
INPUT " n1 , p1 "; n1, p1
INPUT " n2 , p2 "; n2, p2
DIM px(n1), py(n2)
px(0) = (1 - p1) ^ n1
FOR j = 0 TO n1 - 1
px(j + 1) = px(j) * (n1 - j) / (j + 1) * p1 / (1 - p1)
NEXT j
py(0) = (1 - p2) ^ n2
FOR j = 0 TO n2 - 1
py(j + 1) = py(j) * (n2 - j) / (j + 1) * p2 / (1 - p2)
NEXT j
FOR yy = 0 TO n2
c = INT(n1 / n2 * yy)
FOR xx = c TO n1 : s = s + px(xx) * py(yy)
22 NEXT xx
PRINT USING " ### ### #.### "; yy; c; s;
NEXT yy
PRINT s
v = p1 * (1 - p1) / n1 + p2 * (1 - p2) / n2
s = SQR(v) : z = (p1 - p2) / s
PRINT z : END
.



Relevant Pages