num4normality 0.0.6-java → 0.0.7-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9803b3bcb0408424c204ebda20e538aa178a2f35573e280dd222add412987cff
4
- data.tar.gz: 1258e8ad4f82177478d2f35d689f56b4d8d58d1177f7a6f45896f05ee6c50189
3
+ metadata.gz: d445077e57757b20233ab78457bdd1b11a3b1851a8341ab7e28d778ef180d68d
4
+ data.tar.gz: 1e7b9c47b46bffbc4ae6dafa164b6f2b6d3c0707b6ad4478267740248b098498
5
5
  SHA512:
6
- metadata.gz: 16ad0542c142e6b74871df83ae43fa4ac62a9bd977e3bd466b9a520f849f0852460a1b71051b072c5de14b93a4b7530e2ef1821300b7b02303cfd1b307f0a43c
7
- data.tar.gz: c49ca950c085da6760c1d0b171b7daad90354c7804e6521711e7469373a47aca58bec5d7fad47fb5d6c1a882c754ff389bdcae8e957fa93467cdc9db500ffa8a
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
@@ -5,6 +5,7 @@ import org.jfree.data.xy.XYSeriesCollection;
5
5
  import org.jfree.data.xy.XYSeries;
6
6
 
7
7
  import org.jfree.chart.plot.CombinedDomainXYPlot;
8
+ import org.jfree.chart.plot.CombinedRangeXYPlot;
8
9
  import org.jfree.chart.plot.XYPlot;
9
10
  import org.jfree.chart.axis.NumberAxis;
10
11
  import org.jfree.chart.axis.ValueAxis;
@@ -44,10 +45,23 @@ public class Normality {
44
45
  }
45
46
  public static void qqksplot(String dname, double[] xi) {
46
47
  ChartPlot plot = new QQKSChartPlot();
47
- JFreeChart chart = plot.createChart("Q-Q and コルモゴルフ・スミルノフ検定", dname, xi);
48
+ JFreeChart chart = plot.createChart("Q-Q and コルモゴルフ・スミルノフ", dname, xi);
48
49
 
49
50
  plot.writeJPEG("qqksplot.jpeg", chart, 1000, 800);
50
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
+
64
+ }
51
65
  public static boolean kstest(double[] xi) {
52
66
  KSTest ks = new KSTest();
53
67
 
@@ -104,14 +118,6 @@ public class Normality {
104
118
  private static class QQChartPlot implements ChartPlot {
105
119
  public JFreeChart createChart(String title, String dname, double[] xi) {
106
120
  XYPlot plot = createPlot(dname, xi);
107
- /*--- 横軸 ---*/
108
- NumberAxis domainAxis = new NumberAxis("期待値");
109
-
110
- plot.setDomainAxis(domainAxis);
111
- domainAxis.setLowerMargin(0.03);
112
- domainAxis.setUpperMargin(0.03);
113
- domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
114
- domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
115
121
 
116
122
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
117
123
  return new JFreeChart(title, plot);
@@ -122,13 +128,10 @@ public class Normality {
122
128
  return plotImpl.createPlot(dname, xi);
123
129
  }
124
130
  public static class QQPlot implements CreatePlot {
125
- private DescriptiveStatistics stat = null;
126
- private NormalDistribution ndist = null;
127
- public QQPlot() {
128
- stat = new DescriptiveStatistics();
129
- ndist = new NormalDistribution(0, 1);
130
- }
131
131
  private double[][] createData(double[] xi) {
132
+ DescriptiveStatistics stat = new DescriptiveStatistics();
133
+ NormalDistribution ndist = new NormalDistribution(0, 1);
134
+
132
135
  int n = xi.length;
133
136
  Arrays.sort(xi);
134
137
  Arrays.stream(xi).forEach(stat::addValue);
@@ -163,6 +166,15 @@ public class Normality {
163
166
  plot.mapDatasetToRangeAxis(1,0);
164
167
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
165
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
+
166
178
  /*--- 縦軸 ---*/
167
179
  NumberAxis valueAxis0 = new NumberAxis("観測値");
168
180
  plot.setRangeAxis(valueAxis0);
@@ -208,15 +220,7 @@ public class Normality {
208
220
  // コルモゴルフ・スミルノフ検定
209
221
  private static class KSChartPlot implements ChartPlot {
210
222
  public JFreeChart createChart(String title, String dname, double[] xi) {
211
- /*--- 横軸 ---*/
212
- NumberAxis domainAxis = new NumberAxis("期待値");
213
223
  XYPlot plot = createPlot(dname, xi);
214
-
215
- plot.setDomainAxis(domainAxis);
216
- domainAxis.setLowerMargin(0.03);
217
- domainAxis.setUpperMargin(0.03);
218
- domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
219
- domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
220
224
 
221
225
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
222
226
  return new JFreeChart(title, plot);
@@ -227,11 +231,9 @@ public class Normality {
227
231
  return plotImpl.createPlot(dname, xi);
228
232
  }
229
233
  public static class KSPlot implements CreatePlot {
230
- private DescriptiveStatistics stat = null;
231
- public KSPlot() {
232
- stat = new DescriptiveStatistics();
233
- }
234
234
  private double[][] createData(double[] xi) {
235
+ DescriptiveStatistics stat = new DescriptiveStatistics();
236
+
235
237
  int n = xi.length;
236
238
  Arrays.sort(xi);
237
239
  Arrays.stream(xi).forEach(stat::addValue);
@@ -264,6 +266,15 @@ public class Normality {
264
266
  plot.mapDatasetToRangeAxis(1,0);
265
267
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
266
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
+
267
278
  /*--- 縦軸 ---*/
268
279
  NumberAxis valueAxis0 = new NumberAxis("確率");
269
280
  plot.setRangeAxis(valueAxis0);
@@ -307,36 +318,169 @@ public class Normality {
307
318
  }
308
319
  }
309
320
  }
310
- // Q-QandKSplot
321
+ // Q-Q and KSplot
311
322
  private static class QQKSChartPlot implements ChartPlot {
312
- private CreatePlot plot0 = null;
313
- private CreatePlot plot1 = null;
314
- public QQKSChartPlot() {
315
- plot0 = new QQChartPlot.QQPlot();
316
- plot1 = new KSChartPlot.KSPlot();
317
- }
323
+ private CreatePlot plot0 = new QQChartPlot.QQPlot();
324
+ private CreatePlot plot1 = new KSChartPlot.KSPlot();
318
325
  public JFreeChart createChart(String title, String dname, double[] xi) {
319
326
  XYPlot plot = createPlot(dname, xi);
320
327
 
328
+ ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
329
+ return new JFreeChart(title, plot);
330
+ }
331
+ private XYPlot createPlot(String dname, double[] xi) {
321
332
  /*--- 横軸 ---*/
322
- NumberAxis domainAxis = (NumberAxis)plot.getDomainAxis();
333
+ NumberAxis domainAxis = new NumberAxis("期待値");
334
+
335
+ CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis);
323
336
  domainAxis.setLabel("期待値");
324
337
  domainAxis.setLowerMargin(0.03);
325
338
  domainAxis.setUpperMargin(0.03);
326
339
  domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
327
340
  domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
328
341
 
342
+ plot.add(plot0.createPlot(dname, xi), 1);
343
+ plot.add(plot1.createPlot(dname, xi), 1);
344
+ return plot;
345
+ }
346
+
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);
352
+
329
353
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
330
354
  return new JFreeChart(title, plot);
331
355
  }
332
356
  private XYPlot createPlot(String dname, double[] xi) {
333
- CombinedDomainXYPlot plot = new CombinedDomainXYPlot();
357
+ CreatePlot plotImpl = new PPPlot();
334
358
 
335
- plot.add(plot0.createPlot(dname, xi), 1);
336
- plot.add(plot1.createPlot(dname, xi), 1);
337
- return plot;
359
+ return plotImpl.createPlot(dname, xi);
338
360
  }
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);
339
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);
429
+
430
+ for (int i = 0; i < data.length; i++) {
431
+ cu.add(data[i][0], data[i][1]);
432
+ }
433
+ XYSeriesCollection series = new XYSeriesCollection();
434
+
435
+ series.addSeries(cu);
436
+ return series;
437
+ }
438
+ private XYSeriesCollection createDataset1(double[][] data) {
439
+ SimpleRegression simpleReg = new SimpleRegression(true);
440
+ XYSeries cu = new XYSeries("累積");
441
+
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
+
456
+ }
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);
464
+
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);
481
+
482
+ return plot;
483
+ }
340
484
  }
341
485
  // KS検定
342
486
  private static class KSTest {
data/lib/num4normality.rb CHANGED
@@ -39,9 +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を使用
42
54
  def qqksplot(dname, xi)
43
55
  Normality.qqksplot(dname, xi.to_java(Java::double))
44
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
45
87
  # コルモゴルフ・スミルノフ検定(1標本)
46
88
  #
47
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.6
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-23 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