Re: Repeating




"Luis A. Afonso" wrote:
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

What is the parameter p used in the Monte Carlo to generate the data
of x successes out of nX ? You DON'T HAVE a population p for your
Monte Carlo!

This is an exact algorithm but having random errors (RNG).

Example:
Observed 1 out 10, 15 out 30:

from what POPULATION proportion p ???
or POPULATION proportions p1 and p2?

It appears you are making the same mistake of using
SAMPLE proportions as if they were the POPULATION proportions,
as Jack Tomsky had corrected you dozens of times.

-- Reef Fish Bob.

__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)

.



Relevant Pages

  • Kruskal-Wallis test by Monte Carlo? Seems possible.
    ... If we distribute the n ranks rof k samples, with size na distribution of the H´s is constructed under a no distinct difference, with the statistics: ... Simply because the Chi-squared distribution is not EXACT but only APPROXIMATE toward the test statistics.. ... PRINT " Kruskal-Wallis by Monte Carlo" ... IF g< 0 THEN GOTO 5 ...
    (sci.stat.math)
  • Critical values by Monte Carlo
    ... This is a simple problem on Monte Carlo in order to show how a critical value can be evaluated based on simulation.. ... The following step is to add the memory contents till 95000 is obtained or, what is much more likely is just exceeded, getting a value by excess of the cumulative *probability*. ... Zu (evaluation by excess) is more far away from 95000 than Zw providing the argument by defect. ... IF s> vc THEN GOTO 20 ...
    (sci.stat.math)

Loading