11 double *xcopy, sumx = 0.0, sumx2 = 0.0, s2, *
b, *c, *
g, *z, sqrt2;
14 if ((b = (
double *)
malloc(n *
sizeof(
double))) ==
NULL) {
15 fprintf(stderr,
"Memory error in durbins_exact\n");
18 if ((c = (
double *)
malloc((n + 1) *
sizeof(
double))) ==
NULL) {
19 fprintf(stderr,
"Memory error in durbins_exact\n");
22 if ((g = (
double *)
malloc((n + 1) *
sizeof(
double))) ==
NULL) {
23 fprintf(stderr,
"Memory error in durbins_exact\n");
26 if ((z = (
double *)
malloc(n *
sizeof(
double))) ==
NULL) {
27 fprintf(stderr,
"Memory error in durbins_exact\n");
30 if ((xcopy = (
double *)
malloc(n *
sizeof(
double))) ==
NULL) {
31 fprintf(stderr,
"Memory error in durbins_exact\n");
35 sqrt2 = sqrt((
double)2.0);
36 for (i = 0; i <
n; ++i) {
42 s2 = sqrt((sumx2 - sumx * sumx / n) / (n - 1));
43 for (i = 0; i <
n; ++i) {
44 xcopy[i] = (xcopy[i] - sumx /
n) / s2;
45 b[i] = 0.5 +
normp(xcopy[i] / sqrt2) / 2.0;
48 qsort(b, n,
sizeof(
double),
dcmp);
50 for (i = 1; i <
n; ++i)
51 c[i] = b[i] - b[i - 1];
56 qsort(c, n + 1,
sizeof(
double),
dcmp);
58 for (j = 1; j <=
n; ++j)
59 g[j] = (n + 1 - j) * (c[j] - c[j - 1]);
61 g[0] = (n + 1) * c[0];
62 g[
n] = c[
n] - c[n - 1];
64 for (i = 0; i <
n; ++i) {
66 for (j = 0; j <= i; ++j)
69 z[i] = (i + 1.0) / n - z[i];
72 qsort(z, n,
sizeof(
double),
dcmp);
75 y[1] = sqrt((
double)n) * z[n - 1];
78 fprintf(stdout,
" TEST7 DRB(N) =%10.4f\n", y[0]);
int dcmp(const void *i, const void *j)
double * durbins_exact(double *x, int n)