num4normality 0.0.4-java → 0.0.7-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58c526a9c71f5640706a0e7b57c5491b46bc93b7194ed7ef1c6031d49986d0a4
4
- data.tar.gz: 51966044b28deae90af5f764bac62692243312cfcbd6a6013d4a54b8389d009f
3
+ metadata.gz: d445077e57757b20233ab78457bdd1b11a3b1851a8341ab7e28d778ef180d68d
4
+ data.tar.gz: 1e7b9c47b46bffbc4ae6dafa164b6f2b6d3c0707b6ad4478267740248b098498
5
5
  SHA512:
6
- metadata.gz: f7c158d1d3f06e7390757264b06b70ce6081f8d57e4b6d84627a10ba834b1ae8422d38e18216e7faee81f9fc15d649b701af3f42131be504225e31c1131fdc55
7
- data.tar.gz: f109895d5434021a9073180c4717b1db3fa081f9ed89d116d8883ff03318d9be3739f40227f8dc713f8fc576984497bd84889099f9aefec689ee12a60d01978e
6
+ metadata.gz: 5bb019e46c2b0deae1b6f2e2e5776926621620fd787903a3fec119bece63b04e64b979f3c5b3de08883a487fb6ec503d49f43c7acc229b1ab33134c24e5d1179
7
+ data.tar.gz: 8f60222acffc237d2961b909209182cdf9ef2e7fecad9248553be02853c9690cfeefef425f49a4ad5bdff5a0e733d3bd9a434b74b09ef934d94f2ac3f851345b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.7] - 2023-12-26
6
+
7
+ ### add
8
+ - add function of ppplot.
9
+ - add function of ppksplot.
10
+
11
+ ## [0.0.6] - 2023-12-23
12
+
13
+ ### add
14
+ - add function of qqksplot.
15
+
5
16
  ## [0.0.4] - 2023-12-21
6
17
 
7
18
  ### add
@@ -4,6 +4,8 @@ import org.jfree.chart.ChartFactory;
4
4
  import org.jfree.data.xy.XYSeriesCollection;
5
5
  import org.jfree.data.xy.XYSeries;
6
6
 
7
+ import org.jfree.chart.plot.CombinedDomainXYPlot;
8
+ import org.jfree.chart.plot.CombinedRangeXYPlot;
7
9
  import org.jfree.chart.plot.XYPlot;
8
10
  import org.jfree.chart.axis.NumberAxis;
9
11
  import org.jfree.chart.axis.ValueAxis;
@@ -29,17 +31,36 @@ import java.text.DecimalFormat;
29
31
  import org.apache.commons.math3.stat.inference.TestUtils;
30
32
  public class Normality {
31
33
  public static void qqplot(String dname, double[] xi) {
32
- ChartPlot plot = new QQPlot();
33
- JFreeChart chart = plot.createChart(dname, xi);
34
+ ChartPlot plot = new QQChartPlot();
35
+ JFreeChart chart = plot.createChart("正規Q-Qプロット", dname, xi);
34
36
 
35
37
  plot.writeJPEG("qqplot.jpeg", chart, 800, 500);
36
38
  }
37
39
  public static void ksplot(String dname, double[] xi) {
38
- ChartPlot plot = new KSPlot();
39
- JFreeChart chart = plot.createChart(dname, xi);
40
+ ChartPlot plot = new KSChartPlot();
41
+ JFreeChart chart = plot.createChart("コルモゴルフ・スミルノフ検定", dname, xi);
40
42
 
41
43
  plot.writeJPEG("ksplot.jpeg", chart, 800, 500);
42
44
 
45
+ }
46
+ public static void qqksplot(String dname, double[] xi) {
47
+ ChartPlot plot = new QQKSChartPlot();
48
+ JFreeChart chart = plot.createChart("Q-Q and コルモゴルフ・スミルノフ", dname, xi);
49
+
50
+ plot.writeJPEG("qqksplot.jpeg", chart, 1000, 800);
51
+ }
52
+ public static void ppplot(String dname, double[] xi) {
53
+ ChartPlot plot = new PPChartPlot();
54
+ JFreeChart chart = plot.createChart("正規P-Pプロット", dname, xi);
55
+
56
+ plot.writeJPEG("ppplot.jpeg", chart, 800, 500);
57
+ }
58
+ public static void ppksplot(String dname, double[] xi) {
59
+ ChartPlot plot = new PPKSChartPlot();
60
+ JFreeChart chart = plot.createChart("P-P and コルモゴルフ・スミルノフ", dname, xi);
61
+
62
+ plot.writeJPEG("ppksplot.jpeg", chart, 800, 500);
63
+
43
64
  }
44
65
  public static boolean kstest(double[] xi) {
45
66
  KSTest ks = new KSTest();
@@ -65,13 +86,15 @@ public class Normality {
65
86
  return daigo.test(x, 0.05);
66
87
  }
67
88
 
68
-
89
+ /*********************************/
90
+ /* interface define */
91
+ /*********************************/
69
92
  private interface ChartPlot {
70
93
  /* フィールド */
71
94
  static final double CLASS_MIN = -4.0;
72
95
  static final double CLASS_MAX = 4.0;
73
96
  /* メゾット */
74
- JFreeChart createChart(String dname, double[] xi);
97
+ JFreeChart createChart(String title, String dname, double[] xi);
75
98
  default void writeJPEG(String fname, JFreeChart chart, int width, int height) {
76
99
  File file = new File(fname);
77
100
  try {
@@ -81,195 +104,385 @@ public class Normality {
81
104
  }
82
105
  }
83
106
  }
107
+ private interface CreatePlot {
108
+ XYPlot createPlot(String dname, double[] xi);
109
+ }
84
110
  private interface DAgostinosTest {
85
111
  double calcTestStatistic(double[] xi);
86
112
  boolean test(double statistic, double a);
87
113
  }
88
-
114
+ /*********************************/
115
+ /* Class define */
116
+ /*********************************/
89
117
  // Q-Qplot
90
- private static class QQPlot implements ChartPlot {
91
- private DescriptiveStatistics stat = null;
92
- private NormalDistribution ndist = null;
93
- public QQPlot() {
94
- stat = new DescriptiveStatistics();
95
- ndist = new NormalDistribution(0, 1);
96
- }
97
- private double[][] createData(double[] xi) {
98
- int n = xi.length;
99
- Arrays.sort(xi);
100
- Arrays.stream(xi).forEach(stat::addValue);
101
- double sum = stat.getSum();
102
- double[][] data = new double[n][2];
103
- double p = 0.0;
104
-
105
- for (int i = 0; i < n; i++) {
106
- p += xi[i] / sum;
107
- double x =
108
- ndist.inverseCumulativeProbability(p * (i + 1.0) / (n + 1.0));
118
+ private static class QQChartPlot implements ChartPlot {
119
+ public JFreeChart createChart(String title, String dname, double[] xi) {
120
+ XYPlot plot = createPlot(dname, xi);
109
121
 
110
- data[i][0] = x;
111
- data[i][1] = xi[i];
112
- }
113
- return data;
122
+ ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
123
+ return new JFreeChart(title, plot);
114
124
  }
115
- public JFreeChart createChart(String dname, double[] xi) {
116
- double[][] data = createData(xi);
125
+ private XYPlot createPlot(String dname, double[] xi) {
126
+ CreatePlot plotImpl = new QQPlot();
117
127
 
118
- XYPlot plot = createPlot(dname, data);
119
- /*--- 横軸 ---*/
120
- NumberAxis domainAxis = new NumberAxis("標準正規分布");
128
+ return plotImpl.createPlot(dname, xi);
129
+ }
130
+ public static class QQPlot implements CreatePlot {
131
+ private double[][] createData(double[] xi) {
132
+ DescriptiveStatistics stat = new DescriptiveStatistics();
133
+ NormalDistribution ndist = new NormalDistribution(0, 1);
134
+
135
+ int n = xi.length;
136
+ Arrays.sort(xi);
137
+ Arrays.stream(xi).forEach(stat::addValue);
138
+ double sum = stat.getSum();
139
+ double[][] data = new double[n][2];
140
+ double p = 0.0;
141
+
142
+ for (int i = 0; i < n; i++) {
143
+ p += xi[i] / sum;
144
+ double x =
145
+ ndist.inverseCumulativeProbability(p * (i + 1.0) / (n + 1.0));
146
+
147
+ data[i][0] = x;
148
+ data[i][1] = xi[i];
149
+ }
150
+ return data;
151
+ }
152
+ public XYPlot createPlot(String dname, double[] xi) {
153
+ double[][] data = createData(xi);
154
+ XYItemRenderer renderer0 = new XYLineAndShapeRenderer(false, true);
155
+ XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
156
+ XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
157
+
158
+ renderer0.setDefaultToolTipGenerator(toolTipGenerator);
159
+ renderer0.setURLGenerator(null);
160
+ renderer1.setDefaultToolTipGenerator(toolTipGenerator);
161
+ renderer1.setURLGenerator(null);
162
+
163
+ XYPlot plot = new XYPlot();
164
+ plot.setOrientation(PlotOrientation.VERTICAL);
165
+ plot.mapDatasetToRangeAxis(0,0);
166
+ plot.mapDatasetToRangeAxis(1,0);
167
+ plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
168
+
169
+ /*--- 横軸 ---*/
170
+ NumberAxis domainAxis = new NumberAxis("期待値");
171
+
172
+ plot.setDomainAxis(domainAxis);
173
+ domainAxis.setLowerMargin(0.03);
174
+ domainAxis.setUpperMargin(0.03);
175
+ domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
176
+ domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
177
+
178
+ /*--- 縦軸 ---*/
179
+ NumberAxis valueAxis0 = new NumberAxis("観測値");
180
+ plot.setRangeAxis(valueAxis0);
181
+
182
+ plot.setRenderer(0, renderer0);
183
+ plot.setDataset(0, createDataset0(dname, data));
184
+
185
+ plot.setRenderer(1, renderer1);
186
+ plot.setDataset(1, createDataset1(data));
187
+
188
+ return plot;
189
+ }
190
+ private XYSeriesCollection createDataset0(String dname, double[][] data) {
191
+ XYSeries cu = new XYSeries(dname);
192
+
193
+ for (int i = 0; i < data.length; i++) {
194
+ cu.add(data[i][0], data[i][1]);
195
+ }
196
+ XYSeriesCollection series = new XYSeriesCollection();
121
197
 
122
- plot.setDomainAxis(domainAxis);
123
- domainAxis.setLowerMargin(0.03);
124
- domainAxis.setUpperMargin(0.03);
125
- domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
126
- domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
198
+ series.addSeries(cu);
199
+ return series;
200
+ }
201
+ private XYSeriesCollection createDataset1(double[][] data) {
202
+ SimpleRegression simpleReg = new SimpleRegression(true);
203
+ XYSeries cu = new XYSeries("累積");
127
204
 
205
+ simpleReg.addData(data);
206
+ double a = simpleReg.getSlope();
207
+ double b = simpleReg.getIntercept();
208
+
209
+ for (double x = ChartPlot.CLASS_MIN; x < ChartPlot.CLASS_MAX; x += 0.01) {
210
+ double y = a * x + b;
211
+
212
+ cu.add(x, y);
213
+ }
214
+ XYSeriesCollection series = new XYSeriesCollection();
215
+ series.addSeries(cu);
216
+ return series;
217
+ }
218
+ }
219
+ }
220
+ // コルモゴルフ・スミルノフ検定
221
+ private static class KSChartPlot implements ChartPlot {
222
+ public JFreeChart createChart(String title, String dname, double[] xi) {
223
+ XYPlot plot = createPlot(dname, xi);
224
+
128
225
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
129
- return new JFreeChart("正規性の検定", plot);
226
+ return new JFreeChart(title, plot);
130
227
  }
131
- private XYPlot createPlot(String dname, double[][] data) {
132
- XYItemRenderer renderer0 = new XYLineAndShapeRenderer(false, true);
133
- XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
134
- XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
135
-
136
- renderer0.setDefaultToolTipGenerator(toolTipGenerator);
137
- renderer0.setURLGenerator(null);
138
- renderer1.setDefaultToolTipGenerator(toolTipGenerator);
139
- renderer1.setURLGenerator(null);
140
-
141
- XYPlot plot = new XYPlot();
142
- plot.setOrientation(PlotOrientation.VERTICAL);
143
- plot.mapDatasetToRangeAxis(0,0);
144
- plot.mapDatasetToRangeAxis(1,0);
145
- plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
146
-
147
- /*--- 縦軸 ---*/
148
- NumberAxis valueAxis0 = new NumberAxis("観測値");
149
- plot.setRangeAxis(valueAxis0);
228
+ private XYPlot createPlot(String dname, double[] xi) {
229
+ CreatePlot plotImpl = new KSPlot();
150
230
 
151
- plot.setRenderer(0, renderer0);
152
- plot.setDataset(0, createDataset0(dname, data));
231
+ return plotImpl.createPlot(dname, xi);
232
+ }
233
+ public static class KSPlot implements CreatePlot {
234
+ private double[][] createData(double[] xi) {
235
+ DescriptiveStatistics stat = new DescriptiveStatistics();
236
+
237
+ int n = xi.length;
238
+ Arrays.sort(xi);
239
+ Arrays.stream(xi).forEach(stat::addValue);
240
+ double m = stat.getMean(); // 平均
241
+ double sd = stat.getStandardDeviation();// 標準偏差
242
+ double sum = stat.getSum();
243
+ double[][] data = new double[n][2];
244
+ double p = 0.0;
245
+
246
+ for (int i = 0; i < n; i++) {
247
+ p += xi[i] / sum;
248
+ data[i][0] = (xi[i] - m) / sd;
249
+ data[i][1] = p;
250
+ }
251
+ return data;
252
+ }
253
+ public XYPlot createPlot(String dname, double[] xi) {
254
+ XYItemRenderer renderer0 = new XYLineAndShapeRenderer(false, true);
255
+ XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
256
+ XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
257
+
258
+ renderer0.setDefaultToolTipGenerator(toolTipGenerator);
259
+ renderer0.setURLGenerator(null);
260
+ renderer1.setDefaultToolTipGenerator(toolTipGenerator);
261
+ renderer1.setURLGenerator(null);
262
+
263
+ XYPlot plot = new XYPlot();
264
+ plot.setOrientation(PlotOrientation.VERTICAL);
265
+ plot.mapDatasetToRangeAxis(0,0);
266
+ plot.mapDatasetToRangeAxis(1,0);
267
+ plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
268
+
269
+ /*--- 横軸 ---*/
270
+ NumberAxis domainAxis = new NumberAxis("期待値");
271
+ plot.setDomainAxis(domainAxis);
272
+
273
+ domainAxis.setLowerMargin(0.03);
274
+ domainAxis.setUpperMargin(0.03);
275
+ domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
276
+ domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
277
+
278
+ /*--- 縦軸 ---*/
279
+ NumberAxis valueAxis0 = new NumberAxis("確率");
280
+ plot.setRangeAxis(valueAxis0);
281
+ valueAxis0.setLowerBound(0);
282
+ valueAxis0.setUpperBound(1);
283
+ valueAxis0.setTickUnit(new NumberTickUnit(0.1));
284
+ valueAxis0.setNumberFormatOverride(new DecimalFormat("0.0#"));
285
+
286
+ plot.setRenderer(0, renderer0);
287
+ plot.setDataset(0, createDataset0(dname, createData(xi)));
288
+
289
+ plot.setRenderer(1, renderer1);
290
+ plot.setDataset(1, createDataset1());
291
+
292
+ return plot;
293
+ }
294
+ private XYSeriesCollection createDataset0(String dname, double[][] data) {
295
+ XYSeries cu = new XYSeries(dname);
153
296
 
154
- plot.setRenderer(1, renderer1);
155
- plot.setDataset(1, createDataset1(data));
297
+ for (int i = 0; i < data.length; i++) {
298
+ cu.add(data[i][0], data[i][1]);
299
+ }
300
+ XYSeriesCollection series = new XYSeriesCollection();
156
301
 
157
- return plot;
158
- }
159
- private XYSeriesCollection createDataset0(String dname, double[][] data) {
160
- XYSeries cu = new XYSeries(dname);
161
-
162
- for (int i = 0; i < data.length; i++) {
163
- cu.add(data[i][0], data[i][1]);
302
+ series.addSeries(cu);
303
+ return series;
164
304
  }
165
- XYSeriesCollection series = new XYSeriesCollection();
305
+ private XYSeriesCollection createDataset1() {
306
+ NormalDistribution ndist = new NormalDistribution(0, 1);
307
+ XYSeries cu = new XYSeries("累積p");
166
308
 
167
- series.addSeries(cu);
168
- return series;
169
- }
170
- private XYSeriesCollection createDataset1(double[][] data) {
171
- SimpleRegression simpleReg = new SimpleRegression(true);
172
- XYSeries cu = new XYSeries("累積");
309
+ for (double x = ChartPlot.CLASS_MIN; x < ChartPlot.CLASS_MAX; x += 0.01) {
310
+ double y = ndist.cumulativeProbability(x);
173
311
 
174
- simpleReg.addData(data);
175
- double a = simpleReg.getSlope();
176
- double b = simpleReg.getIntercept();
177
-
178
- for (double x = ChartPlot.CLASS_MIN; x < ChartPlot.CLASS_MAX; x += 0.01) {
179
- double y = a * x + b;
312
+ cu.add(x, y);
313
+ }
314
+ XYSeriesCollection series = new XYSeriesCollection();
180
315
 
181
- cu.add(x, y);
316
+ series.addSeries(cu);
317
+ return series;
182
318
  }
183
- XYSeriesCollection series = new XYSeriesCollection();
184
- series.addSeries(cu);
185
- return series;
186
319
  }
187
320
  }
188
- // コルモゴルフ・スミルノフ検定
189
- private static class KSPlot implements ChartPlot {
190
- public JFreeChart createChart(String dname, double[] xi) {
191
- NumberAxis domainAxis = new NumberAxis("標準正規分布");
321
+ // Q-Q and KSplot
322
+ private static class QQKSChartPlot implements ChartPlot {
323
+ private CreatePlot plot0 = new QQChartPlot.QQPlot();
324
+ private CreatePlot plot1 = new KSChartPlot.KSPlot();
325
+ public JFreeChart createChart(String title, String dname, double[] xi) {
192
326
  XYPlot plot = createPlot(dname, xi);
193
-
194
- /*--- 横軸 ---*/
195
- plot.setDomainAxis(domainAxis);
196
- domainAxis.setLowerMargin(0.03);
197
- domainAxis.setUpperMargin(0.03);
198
- domainAxis.setLowerBound(-4);
199
- domainAxis.setUpperBound(4);
200
327
 
201
328
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
202
- return new JFreeChart("コルモゴルフ・スミルノフ検定", plot);
329
+ return new JFreeChart(title, plot);
203
330
  }
204
331
  private XYPlot createPlot(String dname, double[] xi) {
205
- XYItemRenderer renderer0 = new XYLineAndShapeRenderer(false, true);
206
- XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
207
- XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
208
-
209
- renderer0.setDefaultToolTipGenerator(toolTipGenerator);
210
- renderer0.setURLGenerator(null);
211
- renderer1.setDefaultToolTipGenerator(toolTipGenerator);
212
- renderer1.setURLGenerator(null);
332
+ /*--- 横軸 ---*/
333
+ NumberAxis domainAxis = new NumberAxis("期待値");
213
334
 
214
- XYPlot plot = new XYPlot();
215
- plot.setOrientation(PlotOrientation.VERTICAL);
216
- plot.mapDatasetToRangeAxis(0,0);
217
- plot.mapDatasetToRangeAxis(1,0);
218
- plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
335
+ CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis);
336
+ domainAxis.setLabel("期待値");
337
+ domainAxis.setLowerMargin(0.03);
338
+ domainAxis.setUpperMargin(0.03);
339
+ domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
340
+ domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
219
341
 
220
- /*--- 縦軸 ---*/
221
- NumberAxis valueAxis0 = new NumberAxis("確率");
222
- plot.setRangeAxis(valueAxis0);
223
- valueAxis0.setLowerBound(0);
224
- valueAxis0.setUpperBound(1);
225
- valueAxis0.setTickUnit(new NumberTickUnit(0.1));
226
- valueAxis0.setNumberFormatOverride(new DecimalFormat("0.0#"));
342
+ plot.add(plot0.createPlot(dname, xi), 1);
343
+ plot.add(plot1.createPlot(dname, xi), 1);
344
+ return plot;
345
+ }
227
346
 
228
- plot.setRenderer(0, renderer0);
229
- plot.setDataset(0, createDataset0(dname, xi));
347
+ }
348
+ // P-Pplot
349
+ private static class PPChartPlot implements ChartPlot {
350
+ public JFreeChart createChart(String title, String dname, double[] xi) {
351
+ XYPlot plot = createPlot(dname, xi);
230
352
 
231
- plot.setRenderer(1, renderer1);
232
- plot.setDataset(1, createDataset1());
353
+ ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
354
+ return new JFreeChart(title, plot);
355
+ }
356
+ private XYPlot createPlot(String dname, double[] xi) {
357
+ CreatePlot plotImpl = new PPPlot();
233
358
 
234
- return plot;
359
+ return plotImpl.createPlot(dname, xi);
235
360
  }
236
- private XYSeriesCollection createDataset0(String dname, double[] xi) {
237
- int n = xi.length;
238
- Arrays.sort(xi);
239
- DescriptiveStatistics stat = new DescriptiveStatistics();
240
- Arrays.stream(xi).forEach(stat::addValue);
241
- double m = stat.getMean(); // 平均
242
- double sd = stat.getStandardDeviation();// 標準偏差
243
- double sum = stat.getSum();
244
- double p = 0.0;
361
+ public static class PPPlot implements CreatePlot {
362
+ private double[][] createData(double[] xi) {
363
+ DescriptiveStatistics stat = new DescriptiveStatistics();
364
+ NormalDistribution ndist = new NormalDistribution(0, 1);
365
+
366
+ int n = xi.length;
367
+ Arrays.sort(xi);
368
+ Arrays.stream(xi).forEach(stat::addValue);
369
+ double m = stat.getMean(); // 平均
370
+ double sd = stat.getStandardDeviation();// 標準偏差
371
+ double sum = stat.getSum();
372
+ double[][] data = new double[n][2];
373
+ double p = 0.0;
374
+
375
+ for (int i = 0; i < n; i++) {
376
+ p += xi[i] / sum;
377
+ double x = (xi[i] - m) / sd;
378
+
379
+ ndist.cumulativeProbability(x);
380
+ data[i][0] = ndist.cumulativeProbability(x);
381
+ data[i][1] = p;
382
+ }
383
+ return data;
384
+ }
385
+ public XYPlot createPlot(String dname, double[] xi) {
386
+ double[][] data = createData(xi);
387
+ XYItemRenderer renderer0 = new XYLineAndShapeRenderer(false, true);
388
+ XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
389
+ XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
390
+
391
+ renderer0.setDefaultToolTipGenerator(toolTipGenerator);
392
+ renderer0.setURLGenerator(null);
393
+ renderer1.setDefaultToolTipGenerator(toolTipGenerator);
394
+ renderer1.setURLGenerator(null);
395
+
396
+ XYPlot plot = new XYPlot();
397
+ plot.setOrientation(PlotOrientation.VERTICAL);
398
+ plot.mapDatasetToRangeAxis(0,0);
399
+ plot.mapDatasetToRangeAxis(1,0);
400
+ plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
401
+
402
+ /*--- 横軸 ---*/
403
+ NumberAxis domainAxis = new NumberAxis("観測累積確率");
404
+
405
+ plot.setDomainAxis(0, domainAxis);
406
+ domainAxis.setLowerMargin(0.03);
407
+ domainAxis.setUpperMargin(0.03);
408
+ domainAxis.setLowerBound(0.0);
409
+ domainAxis.setUpperBound(1.0);
410
+ domainAxis.setTickUnit(new NumberTickUnit(0.1));
411
+ domainAxis.setNumberFormatOverride(new DecimalFormat("0.0#"));
412
+ /*--- 縦軸 ---*/
413
+ NumberAxis valueAxis0 = new NumberAxis("予測累積確率");
414
+ plot.setRangeAxis(valueAxis0);
415
+ valueAxis0.setLowerBound(0);
416
+ valueAxis0.setUpperBound(1);
417
+ valueAxis0.setTickUnit(new NumberTickUnit(0.1));
418
+ valueAxis0.setNumberFormatOverride(new DecimalFormat("0.0#"));
419
+
420
+ plot.setRenderer(0, renderer0);
421
+ plot.setDataset(0, createDataset0(dname, data));
422
+
423
+ plot.setRenderer(1, renderer1);
424
+ plot.setDataset(1, createDataset1(data));
425
+ return plot;
426
+ }
427
+ private XYSeriesCollection createDataset0(String dname, double[][] data) {
428
+ XYSeries cu = new XYSeries(dname);
245
429
 
246
- XYSeries cu = new XYSeries(dname);
247
- for (int i = 0; i < n; i++) {
248
- double x = (xi[i] - m) / sd;
430
+ for (int i = 0; i < data.length; i++) {
431
+ cu.add(data[i][0], data[i][1]);
432
+ }
433
+ XYSeriesCollection series = new XYSeriesCollection();
249
434
 
250
- p += xi[i] / sum;
251
- cu.add(x, p);
435
+ series.addSeries(cu);
436
+ return series;
252
437
  }
253
- XYSeriesCollection series = new XYSeriesCollection();
438
+ private XYSeriesCollection createDataset1(double[][] data) {
439
+ SimpleRegression simpleReg = new SimpleRegression(true);
440
+ XYSeries cu = new XYSeries("累積");
254
441
 
255
- series.addSeries(cu);
256
- return series;
442
+ simpleReg.addData(data);
443
+ double a = simpleReg.getSlope();
444
+ double b = simpleReg.getIntercept();
445
+
446
+ for (double x = ChartPlot.CLASS_MIN; x < ChartPlot.CLASS_MAX; x += 0.01) {
447
+ double y = a * x + b;
448
+
449
+ cu.add(x, y);
450
+ }
451
+ XYSeriesCollection series = new XYSeriesCollection();
452
+ series.addSeries(cu);
453
+ return series;
454
+ }
455
+
257
456
  }
258
- private XYSeriesCollection createDataset1() {
259
- NormalDistribution ndist = new NormalDistribution(0, 1);
260
- XYSeries cu = new XYSeries("累積p");
261
-
262
- for (double x = -4; x < 4; x += 0.01) {
263
- double y = ndist.cumulativeProbability(x);
457
+ }
458
+ // P-P and KSplot
459
+ private static class PPKSChartPlot implements ChartPlot {
460
+ private CreatePlot plot0 = new PPChartPlot.PPPlot();
461
+ private CreatePlot plot1 = new KSChartPlot.KSPlot();
462
+ public JFreeChart createChart(String title, String dname, double[] xi) {
463
+ XYPlot plot = createPlot(dname, xi);
264
464
 
265
- cu.add(x, y);
266
- }
267
- XYSeriesCollection series = new XYSeriesCollection();
465
+ ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
466
+ return new JFreeChart(title, plot);
467
+ }
468
+ private XYPlot createPlot(String dname, double[] xi) {
469
+ /*--- 縦軸 ---*/
470
+ NumberAxis rangeAxis = new NumberAxis("予測累積確率");
471
+ CombinedRangeXYPlot plot = new CombinedRangeXYPlot(rangeAxis);
472
+ rangeAxis.setLowerMargin(0.03);
473
+ rangeAxis.setUpperMargin(0.03);
474
+ rangeAxis.setLowerBound(0.0);
475
+ rangeAxis.setUpperBound(1.0);
476
+ rangeAxis.setTickUnit(new NumberTickUnit(0.1));
477
+ rangeAxis.setNumberFormatOverride(new DecimalFormat("0.0#"));
478
+
479
+ plot.add(plot0.createPlot(dname, xi), 2);
480
+ plot.add(plot1.createPlot(dname, xi), 3);
268
481
 
269
- series.addSeries(cu);
270
- return series;
482
+ return plot;
271
483
  }
272
484
  }
485
+ // KS検定
273
486
  private static class KSTest {
274
487
  public boolean test(double[] xi) {
275
488
  double[] data = new double[xi.length];
data/lib/num4normality.rb CHANGED
@@ -39,6 +39,51 @@ module Num4NormalityLib
39
39
  def ksplot(dname, xi)
40
40
  Normality.ksplot(dname, xi.to_java(Java::double))
41
41
  end
42
+ # Q-Q and コルモゴルフ・スミルノフ検定プロット(1標本)
43
+ #
44
+ # @overload qqksplot(dname, xi)
45
+ # @param [String] dname データ名
46
+ # @param [Array] xi データ(double[])
47
+ # @return [void] qqksplot.jpegファイルを出力
48
+ # @example
49
+ # xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
50
+ # Num4NormalityLib.qqksplot("LDH", xi)
51
+ # => qqksplot.jpeg
52
+ # @note
53
+ # グラフは、jfreechartを使用
54
+ def qqksplot(dname, xi)
55
+ Normality.qqksplot(dname, xi.to_java(Java::double))
56
+ end
57
+ # P-Pプロット
58
+ #
59
+ # @overload ppplot(dname, xi)
60
+ # @param [String] dname データ名
61
+ # @param [Array] xi データ(double[])
62
+ # @return [void] ppplot.jpegファイルを出力
63
+ # @example
64
+ # xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
65
+ # Num4NormalityLib.ppplot("LDH", xi)
66
+ # => ppplot.jpeg
67
+ # @note
68
+ # グラフは、jfreechartを使用
69
+ def ppplot(dname, xi)
70
+ Normality.ppplot(dname, xi.to_java(Java::double))
71
+ end
72
+ # P-P and コルモゴルフ・スミルノフ検定プロット(1標本)
73
+ #
74
+ # @overload ppksplot(dname, xi)
75
+ # @param [String] dname データ名
76
+ # @param [Array] xi データ(double[])
77
+ # @return [void] ppplot.jpegファイルを出力
78
+ # @example
79
+ # xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
80
+ # Num4NormalityLib.ppksplot("LDH", xi)
81
+ # => ppksplot.jpeg
82
+ # @note
83
+ # グラフは、jfreechartを使用
84
+ def ppksplot(dname, xi)
85
+ Normality.ppksplot(dname, xi.to_java(Java::double))
86
+ end
42
87
  # コルモゴルフ・スミルノフ検定(1標本)
43
88
  #
44
89
  # @overload kstest(xi)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4normality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-20 00:00:00.000000000 Z
11
+ date: 2023-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake