SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GofFormat.java
1/*
2 * Class: GofFormat
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.gof;
26
27import cern.colt.list.*;
28import umontreal.ssj.util.PrintfFormat;
29import umontreal.ssj.probdist.*;
30import java.io.PrintWriter;
31
64public class GofFormat {
65 private GofFormat() {
66 }
67
71
75 public static final int GNUPLOT = 0;
76
80 public static final int MATHEMATICA = 1;
81
91 public static int graphSoft = GNUPLOT;
92
93 private static String formatMath2(double x, double y) {
94 // Writes the pair (x, y) in file f, in a format understood
95 // by Mathematica
96 StringBuffer sb = new StringBuffer();
97 String S;
98
99 sb.append(" { ");
100 if ((x != 0.0) && (x < 0.1 || x > 1.0)) {
101 S = PrintfFormat.E(16, 7, x);
102 int exppos = S.indexOf('E');
103 if (exppos != -1)
104 S = S.substring(0, exppos) + "*10^(" + S.substring(exppos + 1) + ")";
105 } else
106 S = PrintfFormat.g(16, 8, x);
107
108 sb.append(S + ", ");
109
110 if (y != 0.0 && (y < 0.1 || y > 1.0)) {
111 S = PrintfFormat.E(16, 7, y);
112 int exppos = S.indexOf('E');
113 if (exppos != -1)
114 S = S.substring(0, exppos) + "*10^(" + S.substring(exppos + 1) + ")";
115 } else
116 S = PrintfFormat.g(16, 8, y);
117
118 sb.append(S + " }");
119 return sb.toString();
120 }
121
122 private static String graphFunc(ContinuousDistribution dist, double a, double b, int m, int mono, String desc) {
123// Renommer drawCDF en fixant mono = 1 et éliminant mono.
124 int i;
125 double yprec, y, x, h;
126 StringBuffer sb = new StringBuffer();
127 String openComment = "";
128 String closeComment = "";
129 String openGraph = "";
130 String closeGraph = "";
131 if (mono != 1 && mono != -1)
132 throw new IllegalArgumentException("mono must be 1 or -1");
133 switch (graphSoft) {
134 case GNUPLOT:
135 openComment = "# ";
136 closeComment = "";
137 openGraph = "";
138 closeGraph = PrintfFormat.NEWLINE;
139 break;
140 case MATHEMATICA:
141 openComment = "(* ";
142 closeComment = " *)";
143 openGraph = "points = { " + PrintfFormat.NEWLINE;
144 closeGraph = "}" + PrintfFormat.NEWLINE;
145 break;
146 }
147
148 sb.append(openComment + "----------------------------------" + closeComment + PrintfFormat.NEWLINE);
149 sb.append(openComment + PrintfFormat.s(-70, desc) + closeComment + PrintfFormat.NEWLINE + PrintfFormat.NEWLINE);
150
151 sb.append(openGraph);
152 h = (b - a) / m;
153 if (mono == 1)
154 yprec = -Double.MAX_VALUE;
155 else if (mono == -1)
156 yprec = Double.MAX_VALUE;
157 else
158 yprec = 0.0;
159
160 for (i = 0; i <= m; i++) {
161 x = a + i * h;
162 y = mono == 1 ? dist.cdf(x) : dist.barF(x);
163 switch (graphSoft) {
164 case MATHEMATICA:
165 sb.append(formatMath2(x, y));
166 if (i < m)
167 sb.append(',');
168 break;
169 default: // Default and GNUPLOT
170 sb.append(PrintfFormat.g(20, 14, x) + " " + PrintfFormat.g(20, 14, y));
171 }
172
173 switch (mono) {
174 case 1:
175 if (y < yprec)
176 sb.append(" " + openComment + " DECREASING" + closeComment);
177 break;
178 case -1:
179 if (y > yprec)
180 sb.append(" " + openComment + " INCREASING" + closeComment);
181 break;
182 default:
183 break;
184 }
185 sb.append(PrintfFormat.NEWLINE);
186 yprec = y;
187 }
188 sb.append(closeGraph);
189 return sb.toString();
190 }
191
210 public static String drawCdf(ContinuousDistribution dist, double a, double b, int m, String desc) {
211 return graphFunc(dist, a, b, m, 1, desc);
212 }
213
232 public static String drawDensity(ContinuousDistribution dist, double a, double b, int m, String desc) {
233 int i;
234 double y, x, h;
235 StringBuffer sb = new StringBuffer();
236 String openComment = "";
237 String closeComment = "";
238 String openGraph = "";
239 String closeGraph = "";
240
241 switch (graphSoft) {
242 case GNUPLOT:
243 openComment = "# ";
244 closeComment = "";
245 openGraph = "";
246 closeGraph = PrintfFormat.NEWLINE;
247 break;
248 case MATHEMATICA:
249 openComment = "(* ";
250 closeComment = " *)";
251 openGraph = "points = { " + PrintfFormat.NEWLINE;
252 closeGraph = "}" + PrintfFormat.NEWLINE;
253 break;
254 }
255
256 sb.append(openComment + "----------------------------------" + closeComment + PrintfFormat.NEWLINE);
257 sb.append(openComment + PrintfFormat.s(-70, desc) + closeComment + PrintfFormat.NEWLINE + PrintfFormat.NEWLINE);
258
259 sb.append(openGraph);
260 h = (b - a) / m;
261
262 for (i = 0; i <= m; i++) {
263 x = a + i * h;
264 y = dist.density(x);
265
266 switch (graphSoft) {
267 case MATHEMATICA:
268 sb.append(formatMath2(x, y));
269 if (i < m)
270 sb.append(',');
271 break;
272 default: // Default and GNUPLOT
273 sb.append(PrintfFormat.g(16, 8, x) + " " + PrintfFormat.g(16, 8, y));
274 }
275 sb.append(PrintfFormat.NEWLINE);
276 }
277 sb.append(closeGraph);
278 return sb.toString();
279 }
280
294 public static String graphDistUnif(DoubleArrayList data, String desc) {
295 double[] u = data.elements();
296 int n = data.size();
297 int i;
298 double unSurN = 1.0 / n;
299 StringBuffer sb = new StringBuffer();
300
301 switch (graphSoft) {
302 case GNUPLOT:
303 sb.append("#----------------------------------" + PrintfFormat.NEWLINE);
304 sb.append("# " + PrintfFormat.s(-70, desc) + PrintfFormat.NEWLINE + PrintfFormat.NEWLINE);
305 sb.append(PrintfFormat.g(16, 8, 0.0) + " " + PrintfFormat.g(16, 8, 0.0) + PrintfFormat.NEWLINE);
306 for (i = 0; i < n; i++)
307 sb.append(
308 PrintfFormat.g(16, 8, u[i]) + " " + PrintfFormat.g(16, 8, (i + 1) * unSurN) + PrintfFormat.NEWLINE);
309
310 sb.append(PrintfFormat.g(16, 8, 1.0) + " " + PrintfFormat.g(16, 8, 1.0) + PrintfFormat.NEWLINE
312 break;
313 case MATHEMATICA:
314 sb.append("(*----------------------------------*)" + PrintfFormat.NEWLINE);
315 sb.append("(* " + PrintfFormat.s(-70, desc) + PrintfFormat.NEWLINE + " *)" + PrintfFormat.NEWLINE
316 + PrintfFormat.NEWLINE + "points = { " + PrintfFormat.NEWLINE);
317
318 sb.append(formatMath2(0.0, 0.0) + "," + PrintfFormat.NEWLINE);
319 for (i = 0; i < n; i++)
320 sb.append(formatMath2(u[i], (i + 1) * unSurN) + "," + PrintfFormat.NEWLINE);
321 sb.append(formatMath2(1.0, 1.0) + PrintfFormat.NEWLINE);
322 break;
323 default:
324 throw new IllegalArgumentException("graphSoft unknown");
325 }
326 return sb.toString();
327 }
328
332
336
346 public static double EPSILONP = 1.0E-15;
347
357 public static double SUSPECTP = 0.01;
358
368 public static String formatp0(double p) {
369 // Formats the p-value of a test, without a descriptor
370 if ((p >= 0.01) && (p <= 0.99))
371 return PrintfFormat.format(8, 2, 1, p);
372 else if (p < EPSILONP)
373 return " eps ";
374 else if (p < 0.01)
375 return PrintfFormat.format(8, 2, 2, p);
376 else if (p >= 1.0 - EPSILONP)
377 return " 1 - eps ";
378 else
379 return " 1 - " + PrintfFormat.g(8, 2, 1.0 - p);
380 }
381
391 public static String formatp1(double p) {
392 // Prints the p-value of a test, with a descriptor.
393 StringBuffer sb = new StringBuffer();
394 sb.append("p-value of test :" + formatp0(p));
395 if (p < SUSPECTP || p > 1.0 - SUSPECTP)
396 sb.append(" *****");
397
399 return sb.toString();
400 }
401
409 public static String formatp2(double x, double p) {
410 // Prints the statistic x and its p-value p.
411 return PrintfFormat.format(8, 2, 1, x) + PrintfFormat.NEWLINE + formatp1(p);
412 }
413
425 public static String formatp3(String testName, double x, double p) {
426 final String SLT = "p-value of test";
427 int l = Math.max(SLT.length(), testName.length());
428 PrintfFormat pf = new PrintfFormat();
429 pf.append(-l, testName).append(" : ").append(8, 2, 1, x).append(PrintfFormat.NEWLINE);
430 pf.append(-l, SLT).append(" : ").append(formatp0(p));
431 if (p < SUSPECTP || p > 1.0 - SUSPECTP)
432 pf.append(" *****");
434 return pf.toString();
435 }
436
448 public static String formatChi2(int k, int d, double chi2) {
449 StringBuffer sb = new StringBuffer();
450 sb.append("Chi2 statistic : " + PrintfFormat.format(8, 2, 1, chi2));
451 sb.append(PrintfFormat.NEWLINE + "p-value : "
452 + formatp0(GofStat.pDisc(ChiSquareDist.cdf(k - 1, d, chi2), ChiSquareDist.barF(k - 1, d, chi2))));
454 return sb.toString();
455 }
456
470 public static String formatKS(int n, double dp, double dm, double d) {
471 // Prints the results of a Kolmogorov-Smirnov test
472 return "Kolmogorov-Smirnov+ statistic = D+ :" + formatp2(dp, KolmogorovSmirnovPlusDist.barF(n, dp))
473 + "Kolmogorov-Smirnov- statistic = D- :" + formatp2(dm, KolmogorovSmirnovPlusDist.barF(n, dm))
474 + "Kolmogorov-Smirnov statistic = D :" + formatp2(d, KolmogorovSmirnovDistQuick.barF(n, d))
476 }
477
490 public static String formatKS(DoubleArrayList data, ContinuousDistribution dist) {
491
492 double[] v = data.elements();
493 int n = data.size();
494
495 DoubleArrayList dataUnif = GofStat.unifTransform(data, dist);
496 dataUnif.quickSortFromTo(0, dataUnif.size() - 1);
497 double[] ret = GofStat.kolmogorovSmirnov(dataUnif);
498 return formatKS(n, ret[0], ret[1], ret[2]);
499 }
500
513 public static String formatKSJumpOne(int n, double a, double dp) {
514 double d = 1.0 - FDist.kolmogorovSmirnovPlusJumpOne(n, a, dp);
515
516 return PrintfFormat.NEWLINE + "Kolmogorov-Smirnov+ statistic = D+ : " + PrintfFormat.g(8, 2, dp)
518 }
519
531 public static String formatKSJumpOne(DoubleArrayList data, ContinuousDistribution dist, double a) {
532
533 double[] v = data.elements();
534 int n = data.size();
535 DoubleArrayList dataUnif = GofStat.unifTransform(data, dist);
536 dataUnif.quickSortFromTo(0, dataUnif.size() - 1);
537 double[] ret = GofStat.kolmogorovSmirnovJumpOne(dataUnif, a);
538 return formatKSJumpOne(n, a, ret[0]);
539 }
540
544
556
560 public static final int KSP = 0;
561
565 public static final int KSM = 1;
566
570 public static final int KS = 2;
571
575 public static final int AD = 3;
576
580 public static final int CM = 4;
581
585 public static final int WG = 5;
586
590 public static final int WU = 6;
591
595 public static final int MEAN = 7;
596
600 public static final int COR = 8;
601
605 public static final int NTESTTYPES = 9;
606
611 public static final String[] TESTNAMES = { "KolmogorovSmirnovPlus", "KolmogorovSmirnovMinus", "KolmogorovSmirnov",
612 "Anderson-Darling", "CramerVon-Mises", "Watson G", "Watson U", "Mean", "Correlation" };
613
621 public static boolean[] activeTests = null;
622
623 private static void initActiveTests() {
624 activeTests = new boolean[NTESTTYPES];
625 for (int i = 0; i < activeTests.length; i++)
626 activeTests[i] = false;
627 activeTests[KSP] = activeTests[KSM] = true;
629 }
630
631 static {
632 initActiveTests();
633 }
634
652 public static void tests(DoubleArrayList sortedData, double[] sVal) {
653 double[] u = sortedData.elements();
654 int n = sortedData.size();
655 int i;
656 double a2 = 0.0, w2, dm = 0.0, dp = 0.0, w;
657 double u1, ui, d2, d1;
658 double sumZ;
659 double unSurN;
660
661 if (n <= 0)
662 throw new IllegalArgumentException("n <= 0");
663 if (sVal.length != NTESTTYPES)
664 throw new IllegalArgumentException("sVal must " + "be of size NTESTTYPES.");
665
666 // We assume that u is already sorted.
667 if (n == 1) {
668 sVal[KSP] = 1.0 - u[0];
669 sVal[MEAN] = u[0];
670 return;
671 }
672 unSurN = 1.0 / n;
673 w2 = unSurN / 12.0;
674 sumZ = 0.0;
675 for (i = 0; i < n; i++) {
676 // Statistics KS
677 d1 = u[i] - i * unSurN;
678 d2 = (i + 1) * unSurN - u[i];
679 if (d1 > dm)
680 dm = d1;
681 if (d2 > dp)
682 dp = d2;
683 // Watson U and G
684 sumZ += u[i];
685 w = u[i] - (i + 0.5) * unSurN;
686 w2 += w * w;
687 // Anderson-Darling
688 ui = u[i];
689 u1 = 1.0 - ui;
690 if (ui < GofStat.EPSILONAD)
691 ui = GofStat.EPSILONAD;
692 else if (u1 < GofStat.EPSILONAD)
693 u1 = GofStat.EPSILONAD;
694 a2 += (2 * i + 1) * Math.log(ui) + (1 + 2 * (n - i - 1)) * Math.log(u1);
695 }
696 if (dm > dp)
697 sVal[KS] = dm;
698 else
699 sVal[KS] = dp;
700 sVal[KSM] = dm;
701 sVal[KSP] = dp;
702 sumZ = sumZ * unSurN - 0.5;
703 sVal[CM] = w2;
704 sVal[WG] = Math.sqrt((double) n) * (dp + sumZ);
705 sVal[WU] = w2 - sumZ * sumZ * n;
706 sVal[AD] = -n - a2 * unSurN;
707 sVal[MEAN] = sumZ + 0.5; // Nouveau ...
708 }
709
720 public static void tests(DoubleArrayList data, ContinuousDistribution dist, double[] sVal) {
721
722 double[] v = data.elements();
723 int n = data.size();
724
725 if (n <= 0)
726 throw new IllegalArgumentException("n <= 0");
727
728 DoubleArrayList sortedData = GofStat.unifTransform(data, dist);
729 sortedData.quickSortFromTo(0, sortedData.size() - 1);
730 tests(sortedData, sVal);
731 if (n == 1)
732 sVal[MEAN] = v[0]; // On veut v[0], pas u[0].
733 }
734
749 public static void activeTests(DoubleArrayList sortedData, double[] sVal, double[] pVal) {
750
751 double[] u = sortedData.elements();
752 int n = sortedData.size();
753
754 if (n <= 0)
755 throw new IllegalArgumentException("n <= 0");
756
757 if (sVal.length != NTESTTYPES || pVal.length != NTESTTYPES)
758 throw new IllegalArgumentException("sVal and pVal must " + "be of length NTESTTYPES.");
759
760 if (n == 1) {
761 sVal[KSP] = 1.0 - u[0];
762 pVal[KSP] = 1.0 - u[0];
763 pVal[MEAN] = pVal[KSP];
764 return;
765 }
766 // We assume that u is already sorted.
767 tests(sortedData, sVal);
768
769 if (activeTests.length != NTESTTYPES) {
770 initActiveTests();
771 System.err.println("activeTests was invalid, it was reinitialized.");
772 }
773
774 if (activeTests[KSP])
775 pVal[KSP] = KolmogorovSmirnovPlusDist.barF(n, sVal[KSP]);
776
777 if (activeTests[KSM])
778 pVal[KSM] = KolmogorovSmirnovPlusDist.barF(n, sVal[KSM]);
779
780 if (activeTests[KS])
781 pVal[KS] = KolmogorovSmirnovDistQuick.barF(n, sVal[KS]);
782
783 if (activeTests[AD])
784 pVal[AD] = AndersonDarlingDistQuick.barF(n, sVal[AD]);
785
786 if (activeTests[CM])
787 pVal[CM] = CramerVonMisesDist.barF(n, sVal[CM]);
788
789 if (activeTests[WG])
790 pVal[WG] = WatsonGDist.barF(n, sVal[WG]);
791
792 if (activeTests[WU])
793 pVal[WU] = WatsonUDist.barF(n, sVal[WU]);
794 }
795
809 public static void activeTests(DoubleArrayList data, ContinuousDistribution dist, double[] sVal, double[] pVal) {
810 double[] v = data.elements();
811 int n = data.size();
812
813 if (n <= 0)
814 throw new IllegalArgumentException("n <= 0");
815
816 DoubleArrayList sortedData = GofStat.unifTransform(data, dist);
817 sortedData.quickSortFromTo(0, sortedData.size() - 1);
818
819 activeTests(sortedData, sVal, pVal);
820 if (n == 1)
821 sVal[MEAN] = v[0];
822 }
823
837 public static String formatActiveTests(int n, double[] sVal, double[] pVal) {
838
839 if (activeTests.length != NTESTTYPES) {
840 initActiveTests();
841 System.err.println("activeTests was invalid, it was reinitialized.");
842 }
843 if (sVal.length != NTESTTYPES || pVal.length != NTESTTYPES)
844 throw new IllegalArgumentException("The length of " + "sVal and pVal must be NTESTTYPES.");
845 if (n == 1)
846 return formatp1(pVal[KSP]);
847
848 StringBuffer sb = new StringBuffer(PrintfFormat.NEWLINE);
849 if (activeTests[KSP])
850 sb.append("Kolmogorov-Smirnov+ statistic = D+ :" + formatp2(sVal[KSP], pVal[KSP]));
851 if (activeTests[KSM])
852 sb.append("Kolmogorov-Smirnov- statistic = D- :" + formatp2(sVal[KSM], pVal[KSM]));
853 if (activeTests[KS])
854 sb.append("Kolmogorov-Smirnov statistic = D :" + formatp2(sVal[KS], pVal[KS]));
855 if (activeTests[AD])
856 sb.append("Anderson-Darling statistic = A2 :" + formatp2(sVal[AD], pVal[AD]));
857 if (activeTests[CM])
858 sb.append("Cramer-von Mises statistic = W2 :" + formatp2(sVal[CM], pVal[CM]));
859 if (activeTests[WG])
860 sb.append("Watson statistic = G :" + formatp2(sVal[WG], pVal[WG]));
861 if (activeTests[WU])
862 sb.append("Watson statistic = U2 :" + formatp2(sVal[WU], pVal[WU]));
863 sb.append(PrintfFormat.NEWLINE);
864 return sb.toString();
865 }
866
887 public static String iterSpacingsTests(DoubleArrayList sortedData, int k, boolean printval, boolean graph,
888 PrintWriter f) {
889
890 int n = sortedData.size();
891
892 DoubleArrayList sortedDataCopy = (DoubleArrayList) sortedData.clone();
893 DoubleArrayList diffArrayList = new DoubleArrayList(sortedData.size() + 2);
894
895 int j;
896 int i;
897 double[] sVal = new double[NTESTTYPES], pVal = new double[NTESTTYPES];
898
899 StringBuffer sb = new StringBuffer(PrintfFormat.NEWLINE);
900
901 for (j = 1; j <= k; j++) {
902 sb.append("-----------------------------------" + PrintfFormat.NEWLINE
903 + "EDF Tests after \"iterateSpacings\", level : " + PrintfFormat.d(2, j) + PrintfFormat.NEWLINE);
904
905 GofStat.diff(sortedDataCopy, diffArrayList, 0, n - 1, 0.0, 1.0);
906 GofStat.iterateSpacings(sortedDataCopy, diffArrayList);
907 sortedDataCopy.quickSortFromTo(0, sortedDataCopy.size() - 1);
908 activeTests(sortedDataCopy, sVal, pVal);
909
910 sb.append(formatActiveTests(n, sVal, pVal));
911 String desc = "Values of Uniforms after iterateSpacings, level " + PrintfFormat.d(2, j);
912 if (printval) {
913 sb.append(desc + PrintfFormat.NEWLINE + "------------------------" + PrintfFormat.NEWLINE);
914 sb.append(sortedDataCopy + PrintfFormat.NEWLINE);
915 }
916 if (graph && f != null)
917 f.print(graphDistUnif(sortedDataCopy, desc));
918 else if (graph && f == null)
919 sb.append(graphDistUnif(sortedDataCopy, desc));
920 }
921 return sb.toString();
922 }
923
937 public static String iterPowRatioTests(DoubleArrayList sortedData, int k, boolean printval, boolean graph,
938 PrintWriter f) {
939
940 int n = sortedData.size();
941 DoubleArrayList sortedDataCopy = (DoubleArrayList) sortedData.clone();
942
943 int i;
944 int j;
945 double[] sVal = new double[NTESTTYPES], pVal = new double[NTESTTYPES];
946
947 StringBuffer sb = new StringBuffer(PrintfFormat.NEWLINE);
948
949 for (i = 1; i <= k; i++) {
950 GofStat.powerRatios(sortedDataCopy);
951 sb.append("-----------------------------------" + PrintfFormat.NEWLINE
952 + "EDF Tests after \"powerRatios\", level : " + PrintfFormat.d(2, i) + PrintfFormat.NEWLINE);
953
954 sortedDataCopy.quickSortFromTo(0, sortedDataCopy.size() - 1);
955
956 activeTests(sortedDataCopy, sVal, pVal);
957 sb.append(formatActiveTests(n, sVal, pVal));
958 String desc = "Values of Uniforms after PowerRatios, level " + PrintfFormat.d(2, i);
959 if (printval) {
960 sb.append(desc + PrintfFormat.NEWLINE + "--------------------------" + PrintfFormat.NEWLINE);
961 sb.append(sortedDataCopy + PrintfFormat.NEWLINE);
962 }
963 if (graph && f != null)
964 f.print(graphDistUnif(sortedDataCopy, desc));
965 else if (graph && f == null)
966 sb.append(graphDistUnif(sortedDataCopy, desc));
967 }
968 return sb.toString();
969 }
970}
971
This class provides methods to compute (or approximate) the distribution functions of special types o...
Definition FDist.java:33
static double kolmogorovSmirnovPlusJumpOne(int N, double a, double x)
Similar to umontreal.ssj.probdist.KolmogorovSmirnovPlusDist but for the case where the distribution f...
Definition FDist.java:68
static void tests(DoubleArrayList data, ContinuousDistribution dist, double[] sVal)
The observations are in data, not necessarily sorted, and their empirical distribution is compared w...
static void tests(DoubleArrayList sortedData, double[] sVal)
Computes all EDF test statistics enumerated above (except COR) to compare the empirical distribution ...
static final int KSP
Kolmogorov-Smirnov+ test.
static final int KS
Kolmogorov-Smirnov test.
static int graphSoft
Environment variable that selects the type of software to be used for plotting the graphs of function...
static final int KSM
Kolmogorov-Smirnov test.
static final int AD
Anderson-Darling test.
static final String[] TESTNAMES
Name of each testType test.
static boolean[] activeTests
The set of EDF tests that are to be performed when calling the methods activeTests,...
static String formatp2(double x, double p)
Returns x on a single line, then go to the next line and calls formatp1.
static String formatp3(String testName, double x, double p)
Formats the test statistic x for a test named testName with.
static String formatKS(DoubleArrayList data, ContinuousDistribution dist)
Computes the KS test statistics to compare the empirical distribution of the observations in data wit...
static final int WG
Watson G test.
static String formatKSJumpOne(int n, double a, double dp)
Similar to formatKS(int,double,double,double), but for the KS statistic defined in ( KSPlusJumpOne )...
static String formatKS(int n, double dp, double dm, double d)
Computes the -values of the three Kolmogorov-Smirnov statistics , , and , whose values are in dp,...
static String formatActiveTests(int n, double[] sVal, double[] pVal)
Gets the -values of the active EDF test statistics, which are in activeTests.
static String iterSpacingsTests(DoubleArrayList sortedData, int k, boolean printval, boolean graph, PrintWriter f)
Repeats the following k times: Applies the GofStat.iterateSpacings transformation to the ,...
static final int WU
Watson U test.
static String formatKSJumpOne(DoubleArrayList data, ContinuousDistribution dist, double a)
Similar to formatKS(DoubleArrayList,ContinuousDistribution), but for defined in ( KSPlusJumpOne ).
static final int GNUPLOT
Data file format used for plotting functions with Gnuplot.
static double EPSILONP
Environment variable used in formatp0 to determine which.
static final int MEAN
Mean.
static final int COR
Correlation.
static void activeTests(DoubleArrayList data, ContinuousDistribution dist, double[] sVal, double[] pVal)
The observations are in data, not necessarily sorted, and we want to compare their empirical distribu...
static double SUSPECTP
Environment variable used in formatp1 to determine which.
static String formatp0(double p)
Returns the -value of a test, in the format "@f$1-p@f$" if is close to 1, and otherwise.
static String graphDistUnif(DoubleArrayList data, String desc)
Formats data to plot the empirical distribution of , which are assumed to be in data[0....
static String drawDensity(ContinuousDistribution dist, double a, double b, int m, String desc)
Formats data to plot the graph of the density over the interval , and returns the result as a String...
static final int MATHEMATICA
Data file format used for creating graphics with Mathematica.
static final int NTESTTYPES
Total number of test types.
static String formatp1(double p)
Returns the string "<tt>p-value of test : </tt>", then calls formatp0 to print , and adds the marker ...
static final int CM
Cramér-von Mises test.
static String iterPowRatioTests(DoubleArrayList sortedData, int k, boolean printval, boolean graph, PrintWriter f)
Similar to iterSpacingsTests, but with the GofStat.powerRatios transformation.
static String formatChi2(int k, int d, double chi2)
Computes the -value of the chi-square statistic chi2 for a test with k intervals.
static void activeTests(DoubleArrayList sortedData, double[] sVal, double[] pVal)
Computes the EDF test statistics by calling tests(DoubleArrayList,double[]), then computes the -value...
static String drawCdf(ContinuousDistribution dist, double a, double b, int m, String desc)
Formats data to plot the graph of the distribution function over the interval , and returns the resu...
This class provides methods to compute several types of EDF goodness-of-fit test statistics and to ap...
Definition GofStat.java:46
static double[] kolmogorovSmirnov(double[] sortedData)
Computes the Kolmogorov-Smirnov (KS) test statistics ,.
Definition GofStat.java:970
static DoubleArrayList unifTransform(DoubleArrayList data, ContinuousDistribution dist)
Applies the probability integral transformation for.
Definition GofStat.java:70
static void iterateSpacings(DoubleArrayList data, DoubleArrayList spacings)
Applies one iteration of the iterated spacings transformation.
Definition GofStat.java:213
static double[] kolmogorovSmirnovJumpOne(DoubleArrayList sortedData, double a)
Compute the KS statistics and defined in the description of the method FDist.kolmogorovSmirnovPlusJ...
static void powerRatios(DoubleArrayList sortedData)
Applies the power ratios transformation described in section 8.4 of Stephens tste86a .
Definition GofStat.java:252
static double pDisc(double pL, double pR)
Computes a variant of the -value whenever a test statistic has a discrete probability distribution.
static double EPSILONAD
Used by andersonDarling(DoubleArrayList).
Definition GofStat.java:880
static void diff(IntArrayList sortedData, IntArrayList spacings, int n1, int n2, int a, int b)
Assumes that the real-valued observations contained in sortedData are already sorted in increasing o...
Definition GofStat.java:126
Extends the class AndersonDarlingDist for the Anderson–Darling distribution (see tand52a,...
double barF(double x)
Returns the complementary distribution function.
Extends the class ContinuousDistribution for the chi-square distribution with degrees of freedom,...
double cdf(double x)
Returns the distribution function .
double barF(double x)
Returns the complementary distribution function.
Classes implementing continuous distributions should inherit from this base class.
abstract double density(double x)
Returns , the density evaluated at .
double barF(double x)
Returns the complementary distribution function.
Extends the class ContinuousDistribution for the Cramér-von Mises distribution (see tdur73a,...
double barF(double x)
Returns the complementary distribution function.
Extends the class KolmogorovSmirnovDist for the Kolmogorov–Smirnov distribution.
double barF(double x)
Returns the complementary distribution function.
Extends the class ContinuousDistribution for the Kolmogorov–Smirnov+ distribution (see tdar60a,...
double barF(double x)
Returns the complementary distribution function.
Extends the class ContinuousDistribution for the Watson distribution (see tdar83a,...
double barF(double x)
Returns the complementary distribution function.
Extends the class ContinuousDistribution for the Watson U distribution (see tdur73a,...
double barF(double x)
Returns the complementary distribution function.
This class acts like a StringBuffer which defines new types of append methods.
String toString()
Converts the buffer into a String.
static String s(String str)
Same as s(0, str).
static String d(long x)
Same as d(0, 1, x).
PrintfFormat append(String str)
Appends str to the buffer.
static final String NEWLINE
End-of-line symbol or line separator.
static String format(long x)
Same as d(0, 1, x).
static String E(double x)
Same as E(0, 6, x).
static String g(double x)
Same as g(0, 6, x).
double cdf(double x)
Returns the distribution function .