4 #include "local_proto.h" 8 static double poly(
double c[],
int nord,
double x);
25 void wext(
double x[],
int n,
double ssq,
double a[],
int n2,
double eps,
26 double *w,
double *pw,
int *ifault)
28 double eu3, lamda, ybar, sdy, al, un, ww, y, z;
30 static double wa[3] = { 0.118898, 0.133414, 0.327907 };
31 static double wb[4] = { -0.37542, -0.492145, -1.124332, -0.199422 };
32 static double wc[4] = { -3.15805, 0.729399, 3.01855, 1.558776 };
33 static double wd[6] = { 0.480385, 0.318828, 0.0, -0.0241665, 0.00879701,
36 static double we[6] = { -1.91487, -1.37888, -0.04183209, 0.1066339,
37 -0.03513666, -0.01504614
39 static double wf[7] = { -3.73538, -1.015807, -0.331885, 0.1773538,
40 -0.01638782, -0.03215018, 0.003852646
42 static double unl[3] = { -3.8, -3.0, -1.0 };
43 static double unh[3] = { 8.6, 5.8, 5.4 };
44 static int nc1[3] = { 5, 5, 5 };
45 static int nc2[3] = { 3, 4, 5 };
48 static double pi6 = 1.90985932, stqr = 1.04719755;
49 static double zero = 0.0, tqr = 0.75, one = 1.0;
50 static double onept4 = 1.4, three = 3.0, five = 5.0;
51 static double c1[5][3] = {
52 {-1.26233, -2.28135, -3.30623},
53 {1.87969, 2.26186, 2.76287},
54 {0.0649583, 0.0, -0.83484},
55 {-0.0475604, 0.0, 1.20857},
56 {-0.0139682, -0.00865763, -0.507590}
58 static double c2[5][3] = {
59 {-0.287696, -1.63638, -5.991908},
60 {1.78953, 5.60924, 21.04575},
61 {-0.180114, -3.63738, -24.58061},
62 {0.0, 1.08439, 13.78661},
85 for (*w = 0.0, j = 0; j < n2; ++j)
86 *w += a[j] * (x[i--] - x[j]);
101 al = log((
double)n) - three;
102 lamda = poly(wa, 3, al);
103 ybar = exp(poly(wb, 4, al));
104 sdy = exp(poly(wc, 4, al));
107 al = log((
double)n) - five;
108 lamda = poly(wd, 6, al);
109 ybar = exp(poly(we, 6, al));
110 sdy = exp(poly(wf, 7, al));
113 y = pow(one - *w, lamda);
114 z = (y - ybar) / sdy;
126 *pw = pi6 * (atan(sqrt(ww / (one - ww))) - stqr);
131 un = log((*w - eps) / (one - *w));
133 if (un >= unl[n3 - 1]) {
137 for (i = 0; i < nc; ++i)
138 c[i] = c1[i][n3 - 1];
140 eu3 = exp(poly(c, nc, un));
143 if (un > unh[n3 - 1])
148 for (i = 0; i < nc; ++i)
149 c[i] = c2[i][n3 - 1];
152 eu3 = exp(exp(poly(c, nc, un)));
154 ww = (eu3 + tqr) / (one + eu3);
155 *pw = pi6 * (atan(sqrt(ww / (one - ww))) - stqr);
175 void wcoef(
double a[],
int n,
int n2,
double *eps,
int *ifault)
177 static double c4[2] = { 0.6869, 0.1678 };
178 static double c5[2] = { 0.6647, 0.2412 };
179 static double c6[3] = { 0.6431, 0.2806, 0.0875 };
180 static double rsqrt2 = 0.70710678;
181 double a1star, a1sq, sastar, an;
201 for (sastar = 0.0, j = 1; j < n2; ++j)
202 sastar += a[j] * a[j];
209 a1sq = exp(log(6.0 * an + 7.0) - log(6.0 * an + 13.0)
210 + 0.5 * (1.0 + (an - 2.0) * log(an + 1.0) - (an - 1.0)
212 a1star = sastar / (1.0 / a1sq - 2.0);
213 sastar = sqrt(sastar + 2.0 * a1star);
214 a[0] = sqrt(a1star) / sastar;
216 for (j = 1; j < n2; ++j)
217 a[j] = 2.0 * a[j] / sastar;
225 for (j = 0; j < 3; ++j)
228 for (j = 0; j < 2; ++j)
231 for (j = 0; j < 2; ++j)
249 *eps = a[0] * a[0] / (1.0 - 1.0 / (double)n);
261 static double poly(
double c[],
int nord,
double x)
275 for (i = 0; i < n2; ++i)
276 p = (p + c[j--]) *
x;
293 void Cdhc_wgp(
double x[],
int n,
double ssq,
double gp,
double h,
double a[],
294 int n2,
double eps,
double w,
double u,
double p,
int *ifault)
296 double zbar, zsd, an1, hh;
306 an1 = (double)(n - 1);
308 ssq = ssq - an1 * gp * gp / 12.0;
309 h = gp / sqrt(ssq / an1);
315 wext(x, n, ssq, a, n2, eps, &w, &p, ifault);
320 if (!(p > 0.0 && p < 1.0)) {
330 zbar = -h * (1.07457 + hh * (-2.8185 + hh * 1.8898));
331 zsd = 1.0 + h * (0.50933 + hh * (-0.98305 + hh * 0.7408));
334 zbar = -h * (0.96436 + hh * (-2.1300 + hh * 1.3196));
335 zsd = 1.0 + h * (0.2579 + h * 0.15225);
340 u = (-
ppnd16(p) - zbar) / zsd;
double Cdhc_alnorm(double x, int upper)
void wext(double x[], int n, double ssq, double a[], int n2, double eps, double *w, double *pw, int *ifault)
void Cdhc_nscor2(double s[], int n, int n2, int *ifault)
void Cdhc_wgp(double x[], int n, double ssq, double gp, double h, double a[], int n2, double eps, double w, double u, double p, int *ifault)
void wcoef(double a[], int n, int n2, double *eps, int *ifault)