Code/pseudo-code for Z-test

11 views
Skip to first unread message

Q Modnar

unread,
Jun 3, 1999, 3:00:00 AM6/3/99
to

Hi, I need to write the Z-test algorithm in the C language. Does anyone know
if there is available some code or pseudo-code on the web? I need it quite
urgently so any help will be appreciated. Thanks.


Angelique Sanders

unread,
Jun 3, 1999, 3:00:00 AM6/3/99
to
Q Modnar (modn...@yahoo.com) wrote:

: Hi, I need to write the Z-test algorithm in the C language. Does anyone know


: if there is available some code or pseudo-code on the web? I need it quite
: urgently so any help will be appreciated. Thanks.

HI Q Modnar -
just look in any intro stats book. The formula is very
simple.

Best wishes,
Kent.

Jan Ritsema van Eck

unread,
Jun 4, 1999, 3:00:00 AM6/4/99
to

Of course, to code a Z-test you need to compute the _cumulative_ density
function. The intro stats books on my book shelf only give the formula
for the normal density function, which isn't much use because you can't
integrate it. There is no simple exact formula for the CDF, although
there are some pretty simple approximations (books with titles like
"statistics with BASIC" usually give some). I posted the following
program in C a few months ago.

jan

---------------------------------------------------------------
# include <math.h>
# define PI 3.14159265
# define PREC 0.00005

double cdf_norm(double x);

main(int argc, char *argv[])
{ double x, y;
x = atof(argv[1]);
y = cdf_norm(x);
printf("P(0.00 < Z < %.2f) = %.2f\%\n", x, 100 * y);
}

double cdf_norm(double x)
{ int i;
double a, b, c, term, sum;
a = b = 1;
c = sum = term = x;
if (fabs(x) > 8) return 0.5 * x / fabs(x);
for (i = 1; fabs(term) > PREC; i++)
{ a += 2;
b *= -2 * i;
c *= x * x;
term = c / (a * b);
sum += term;
}
return sum / sqrt(2 * PI);
}

Reply all
Reply to author
Forward
0 new messages