4 #include "local_proto.h"
7 static double poly(
double c[],
int nord,
double x);
23 void wext(
double x[],
int n,
double ssq,
double a[],
int n2,
double eps,
24 double *w,
double *pw,
int *ifault)
26 double eu3, lamda, ybar, sdy, al, un, ww, y, z;
28 static double wa[3] = {0.118898, 0.133414, 0.327907};
29 static double wb[4] = {-0.37542, -0.492145, -1.124332, -0.199422};
30 static double wc[4] = {-3.15805, 0.729399, 3.01855, 1.558776};
31 static double wd[6] = {0.480385, 0.318828, 0.0,
32 -0.0241665, 0.00879701, 0.002989646};
33 static double we[6] = {-1.91487, -1.37888, -0.04183209,
34 0.1066339, -0.03513666, -0.01504614};
35 static double wf[7] = {-3.73538, -1.015807, -0.331885, 0.1773538,
36 -0.01638782, -0.03215018, 0.003852646};
37 static double unl[3] = {-3.8, -3.0, -1.0};
38 static double unh[3] = {8.6, 5.8, 5.4};
39 static int nc1[3] = {5, 5, 5};
40 static int nc2[3] = {3, 4, 5};
43 static double pi6 = 1.90985932, stqr = 1.04719755;
44 static double zero = 0.0, tqr = 0.75, one = 1.0;
45 static double onept4 = 1.4, three = 3.0, five = 5.0;
47 static double c1[5][3] = {{-1.26233, -2.28135, -3.30623},
48 {1.87969, 2.26186, 2.76287},
49 {0.0649583, 0.0, -0.83484},
50 {-0.0475604, 0.0, 1.20857},
51 {-0.0139682, -0.00865763, -0.507590}};
52 static double c2[5][3] = {{-0.287696, -1.63638, -5.991908},
53 {1.78953, 5.60924, 21.04575},
54 {-0.180114, -3.63738, -24.58061},
55 {0.0, 1.08439, 13.78661},
56 {0.0, 0.0, -2.835295}};
77 for (*w = 0.0, j = 0; j < n2; ++j)
78 *w += a[j] * (
x[i--] -
x[j]);
93 al = log((
double)n) - three;
94 lamda = poly(wa, 3, al);
95 ybar = exp(poly(wb, 4, al));
96 sdy = exp(poly(wc, 4, al));
99 al = log((
double)n) - five;
100 lamda = poly(wd, 6, al);
101 ybar = exp(poly(we, 6, al));
102 sdy = exp(poly(wf, 7, al));
105 y = pow(one - *w, lamda);
106 z = (y - ybar) / sdy;
118 *pw = pi6 * (atan(sqrt(ww / (one - ww))) - stqr);
123 un = log((*w - eps) / (one - *w));
125 if (un >= unl[n3 - 1]) {
129 for (i = 0; i < nc; ++i)
130 c[i] = c1[i][n3 - 1];
132 eu3 = exp(poly(c, nc, un));
135 if (un > unh[n3 - 1])
140 for (i = 0; i < nc; ++i)
141 c[i] = c2[i][n3 - 1];
144 eu3 = exp(exp(poly(c, nc, un)));
146 ww = (eu3 + tqr) / (one + eu3);
147 *pw = pi6 * (atan(sqrt(ww / (one - ww))) - stqr);
166 void wcoef(
double a[],
int n,
int n2,
double *eps,
int *ifault)
168 static double c4[2] = {0.6869, 0.1678};
169 static double c5[2] = {0.6647, 0.2412};
170 static double c6[3] = {0.6431, 0.2806, 0.0875};
171 static double rsqrt2 = 0.70710678;
172 double a1star, a1sq, sastar, an;
193 for (sastar = 0.0, j = 1; j < n2; ++j)
194 sastar += a[j] * a[j];
201 a1sq = exp(log(6.0 * an + 7.0) - log(6.0 * an + 13.0) +
202 0.5 * (1.0 + (an - 2.0) * log(an + 1.0) -
203 (an - 1.0) * log(an + 2.0)));
204 a1star = sastar / (1.0 / a1sq - 2.0);
205 sastar = sqrt(sastar + 2.0 * a1star);
206 a[0] = sqrt(a1star) / sastar;
208 for (j = 1; j < n2; ++j)
209 a[j] = 2.0 * a[j] / sastar;
217 for (j = 0; j < 3; ++j)
220 for (j = 0; j < 2; ++j)
223 for (j = 0; j < 2; ++j)
241 *eps = a[0] * a[0] / (1.0 - 1.0 / (double)n);
252 static double poly(
double c[],
int nord,
double x)
266 for (i = 0; i < n2; ++i)
267 p = (p + c[j--]) *
x;
283 void Cdhc_wgp(
double x[],
int n,
double ssq,
double gp,
double h,
double a[],
284 int n2,
double eps,
double w,
double u,
double p,
int *ifault)
286 double zbar, zsd, an1, hh;
296 an1 = (double)(n - 1);
298 ssq = ssq - an1 * gp * gp / 12.0;
299 h = gp / sqrt(ssq / an1);
305 wext(
x, n, ssq, a, n2, eps, &w, &p, ifault);
310 if (!(p > 0.0 && p < 1.0)) {
320 zbar = -h * (1.07457 + hh * (-2.8185 + hh * 1.8898));
321 zsd = 1.0 + h * (0.50933 + hh * (-0.98305 + hh * 0.7408));
324 zbar = -h * (0.96436 + hh * (-2.1300 + hh * 1.3196));
325 zsd = 1.0 + h * (0.2579 + h * 0.15225);
330 u = (-
ppnd16(p) - zbar) / zsd;
void Cdhc_nscor2(double s[], int n, int n2, int *ifault)
void wext(double x[], int n, double ssq, double a[], int n2, double eps, double *w, double *pw, int *ifault)
void wcoef(double a[], int n, int n2, double *eps, 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)
double Cdhc_alnorm(double x, int upper)