num4normality 0.0.8-java → 0.0.9-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: 6bdb8267fad8c0c825bffbdc4ce48f03b5f7044b42c7b4575acd0c3bd1d24485
4
- data.tar.gz: '0299ec982c1d8c30ee2613f2511d13125c95fb3113ccc48e630ad9496485f92b'
3
+ metadata.gz: 28c1bcf4f9952a2f18587d5b23d301a43ea31cd109d6a2d99ce665f900877bbf
4
+ data.tar.gz: 29a902d3ef52739cb913bc523c5488ebcc14ac3288d8babc8d7e64fd28448cbf
5
5
  SHA512:
6
- metadata.gz: f5d1bb2fb5de97f2480715cff1b0183ff22cf7f04f2d776050edf32f49377bd9dce4b6d48eacdbcde1fe1a67118dcc1e21b1232d84f582a9f65fa695528ca9f5
7
- data.tar.gz: 15d6d2d3bbd2b18361064577273fdb66f43f906ebfa87f9671cc31e9a1a11e3203f16b3c828fe828c87aacfcb9be3663370e6249992bf222eb1265109ea6c038
6
+ metadata.gz: 66fe7346cae038b6a399395d46863b2a7aaecff96687b451075e2affa08236c1f8eb5b18066eed22eafac9f1ac7c719989e43c07082fceb3d17b9b6d4310fe4b
7
+ data.tar.gz: 3b621221e49cfaabf960cb5f8d413aadb53ec1e280e7f3c65b1cb2d70dd8c960129e239aee017365d9910c609b84b35d875f7e12fcc5a3f0f84284db3a9d78b6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.9] - 2024-05-11
6
+ ### add
7
+ - add function of adtest.
8
+
5
9
  ## [0.0.8] - 2023-12-30
6
10
 
7
11
  ### Fixed
@@ -1,6 +1,7 @@
1
1
  import org.jfree.chart.JFreeChart;
2
2
  import org.jfree.chart.StandardChartTheme;
3
3
  import org.jfree.chart.ChartFactory;
4
+ import org.jfree.chart.ChartUtils;
4
5
  import org.jfree.data.xy.XYSeriesCollection;
5
6
  import org.jfree.data.xy.XYSeries;
6
7
 
@@ -25,68 +26,74 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
25
26
  import org.apache.commons.math3.stat.StatUtils;
26
27
  import org.apache.commons.math3.distribution.NormalDistribution;
27
28
  import org.apache.commons.math3.distribution.ChiSquaredDistribution;
29
+ import org.apache.commons.math3.distribution.TDistribution;
28
30
  import org.apache.commons.math3.stat.regression.SimpleRegression;
29
31
  import java.util.Arrays;
30
32
  import java.text.DecimalFormat;
31
33
 
32
34
  import org.apache.commons.math3.stat.inference.TestUtils;
33
35
  public class Normality {
34
- public static void qqplot(String dname, double[] xi) {
36
+ public static void qqPlot(String dname, double[] xi) {
35
37
  ChartPlot plot = new QQChartPlot();
36
38
  JFreeChart chart = plot.createChart("正規Q-Qプロット", dname, xi);
37
39
 
38
40
  plot.writeJPEG("qqplot.jpeg", chart, 800, 500);
39
41
  }
40
- public static void ksplot(String dname, double[] xi) {
42
+ public static void ksPlot(String dname, double[] xi) {
41
43
  ChartPlot plot = new KSChartPlot();
42
44
  JFreeChart chart = plot.createChart("コルモゴルフ・スミルノフ検定", dname, xi);
43
45
 
44
46
  plot.writeJPEG("ksplot.jpeg", chart, 800, 500);
45
47
 
46
48
  }
47
- public static void qqksplot(String dname, double[] xi) {
48
- ChartPlot plot = new QQKSChartPlot();
49
+ public static void qqksPlot(String dname, double[] xi) {
50
+ ChartPlot plot = new QQKSChartPlot();
49
51
  JFreeChart chart = plot.createChart("Q-Q and コルモゴルフ・スミルノフ", dname, xi);
50
52
 
51
53
  plot.writeJPEG("qqksplot.jpeg", chart, 1000, 800);
52
54
  }
53
- public static void ppplot(String dname, double[] xi) {
55
+ public static void ppPlot(String dname, double[] xi) {
54
56
  ChartPlot plot = new PPChartPlot();
55
57
  JFreeChart chart = plot.createChart("正規P-Pプロット", dname, xi);
56
58
 
57
59
  plot.writeJPEG("ppplot.jpeg", chart, 800, 500);
58
60
  }
59
- public static void ppksplot(String dname, double[] xi) {
61
+ public static void ppksPlot(String dname, double[] xi) {
60
62
  ChartPlot plot = new PPKSChartPlot();
61
63
  JFreeChart chart = plot.createChart("P-P and コルモゴルフ・スミルノフ", dname, xi);
62
64
 
63
65
  plot.writeJPEG("ppksplot.jpeg", chart, 800, 500);
64
66
 
65
67
  }
66
- public static boolean kstest(double[] xi) {
68
+ public static boolean ksTest(double[] xi) {
67
69
  KSTest ks = new KSTest();
68
70
 
69
71
  return ks.test(xi);
70
72
  }
71
- public static boolean skewnesstest(double[] xi) {
72
- DAgostinosTest daigo = new SkewnessTest();
73
+ public static boolean skewnessTest(double[] xi) {
74
+ HypothesisTest daigo = new SkewnessTest();
73
75
 
74
76
  double b1 = daigo.calcTestStatistic(xi);
75
- return daigo.test(b1, 0.05);
77
+ return daigo.test(b1, HypothesisTest.P);
76
78
  }
77
- public static boolean kurtosistest(double[] xi) {
78
- DAgostinosTest daigo = new KurtosisTest();
79
+ public static boolean kurtosisTest(double[] xi) {
80
+ HypothesisTest daigo = new KurtosisTest();
79
81
 
80
82
  double b2 = daigo.calcTestStatistic(xi);
81
- return daigo.test(b2, 0.05);
83
+ return daigo.test(b2, HypothesisTest.P);
82
84
  }
83
- public static boolean omnibustest(double[] xi) {
84
- DAgostinosTest daigo = new OmnibusTest();
85
+ public static boolean omnibusTest(double[] xi) {
86
+ HypothesisTest daigo = new OmnibusTest();
85
87
 
86
88
  double x = daigo.calcTestStatistic(xi);
87
- return daigo.test(x, 0.05);
89
+ return daigo.test(x, HypothesisTest.P);
90
+ }
91
+ public static boolean adTest(double[] xi) {
92
+ HypothesisTest daigo = new ADTest();
93
+ double x = daigo.calcTestStatistic(xi);
94
+
95
+ return daigo.test(x, HypothesisTest.P);
88
96
  }
89
-
90
97
  /*********************************/
91
98
  /* interface define */
92
99
  /*********************************/
@@ -108,7 +115,11 @@ public class Normality {
108
115
  private interface CreatePlot {
109
116
  XYPlot createPlot(String dname, double[] xi);
110
117
  }
111
- private interface DAgostinosTest {
118
+ private interface HypothesisTest {
119
+ /* フィールド */
120
+ static final double P = 0.05;
121
+
122
+ /* メゾット */
112
123
  double calcTestStatistic(double[] xi);
113
124
  boolean test(double statistic, double a);
114
125
  }
@@ -121,7 +132,10 @@ public class Normality {
121
132
  XYPlot plot = createPlot(dname, xi);
122
133
 
123
134
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
124
- return new JFreeChart(title, plot);
135
+ JFreeChart chart = new JFreeChart(title, plot);
136
+
137
+ ChartUtils.applyCurrentTheme(chart);
138
+ return chart;
125
139
  }
126
140
  private XYPlot createPlot(String dname, double[] xi) {
127
141
  CreatePlot plotImpl = new QQPlot();
@@ -224,7 +238,10 @@ public class Normality {
224
238
  XYPlot plot = createPlot(dname, xi);
225
239
 
226
240
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
227
- return new JFreeChart(title, plot);
241
+ JFreeChart chart = new JFreeChart(title, plot);
242
+
243
+ ChartUtils.applyCurrentTheme(chart);
244
+ return chart;
228
245
  }
229
246
  private XYPlot createPlot(String dname, double[] xi) {
230
247
  CreatePlot plotImpl = new KSPlot();
@@ -326,7 +343,10 @@ public class Normality {
326
343
  XYPlot plot = createPlot(dname, xi);
327
344
 
328
345
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
329
- return new JFreeChart(title, plot);
346
+ JFreeChart chart = new JFreeChart(title, plot);
347
+
348
+ ChartUtils.applyCurrentTheme(chart);
349
+ return chart;
330
350
  }
331
351
  private XYPlot createPlot(String dname, double[] xi) {
332
352
  /*--- 横軸 ---*/
@@ -351,7 +371,10 @@ public class Normality {
351
371
  XYPlot plot = createPlot(dname, xi);
352
372
 
353
373
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
354
- return new JFreeChart(title, plot);
374
+ JFreeChart chart = new JFreeChart(title, plot);
375
+
376
+ ChartUtils.applyCurrentTheme(chart);
377
+ return chart;
355
378
  }
356
379
  private XYPlot createPlot(String dname, double[] xi) {
357
380
  CreatePlot plotImpl = new PPPlot();
@@ -460,7 +483,10 @@ public class Normality {
460
483
  XYPlot plot = createPlot(dname, xi);
461
484
 
462
485
  ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
463
- return new JFreeChart(title, plot);
486
+ JFreeChart chart = new JFreeChart(title, plot);
487
+
488
+ ChartUtils.applyCurrentTheme(chart);
489
+ return chart;
464
490
  }
465
491
  private XYPlot createPlot(String dname, double[] xi) {
466
492
  /*--- 縦軸 ---*/
@@ -490,7 +516,7 @@ public class Normality {
490
516
  }
491
517
  }
492
518
  // タコスディーノ検定(歪度)
493
- private static class SkewnessTest implements DAgostinosTest {
519
+ private static class SkewnessTest implements HypothesisTest {
494
520
  private long n = 0;
495
521
  private NormalDistribution ndist = null;
496
522
  public SkewnessTest() {
@@ -520,7 +546,7 @@ public class Normality {
520
546
  }
521
547
  }
522
548
  // タコスディーノ検定(尖度)
523
- private static class KurtosisTest implements DAgostinosTest {
549
+ private static class KurtosisTest implements HypothesisTest {
524
550
  private long n = 0;
525
551
  private NormalDistribution ndist = null;
526
552
  public KurtosisTest() {
@@ -550,9 +576,9 @@ public class Normality {
550
576
  }
551
577
  }
552
578
  // オムニバス検定
553
- private static class OmnibusTest implements DAgostinosTest {
554
- private DAgostinosTest skewness = null;
555
- private DAgostinosTest kurtosis = null;
579
+ private static class OmnibusTest implements HypothesisTest {
580
+ private HypothesisTest skewness = null;
581
+ private HypothesisTest kurtosis = null;
556
582
  public OmnibusTest() {
557
583
  skewness = new SkewnessTest();
558
584
  kurtosis = new KurtosisTest();
@@ -570,5 +596,53 @@ public class Normality {
570
596
  return (p < a) ? true : false;
571
597
  }
572
598
  }
599
+ // Anderson-Darling検定
600
+ private static class ADTest implements HypothesisTest {
601
+ public double calcTestStatistic(double[] xi) {
602
+ int n = xi.length;
603
+ double a2 = calcA2(xi, n);
604
+
605
+ return calcAD(a2, n);
606
+ }
607
+ public boolean test(double statistic, double a) {
608
+ double p = 0.0;
609
+ double statistic2 = statistic * statistic;
610
+
611
+ if (statistic <= 0.2) {
612
+ p = 1.0 - Math.exp(-13.436 + 101.14 * statistic - 223.73 * statistic);
613
+ }
614
+ else if ((0.2 < statistic) && (statistic <= 0.34)) {
615
+ p = 1.0 - Math.exp(-8.318 + 42.796 * statistic - 59.938 * statistic2);
616
+ }
617
+ else if ((0.34 < statistic) && (statistic <= 0.6)) {
618
+ p = Math.exp(0.9177 - 4.279 * statistic - 1.38 * statistic2);
619
+ }
620
+ else {
621
+ p = Math.exp(1.2937 - 5.709 * statistic + 0.0186 * statistic2);
622
+ }
623
+ return (p <= a) ? true : false;
624
+ }
625
+ private double calcA2(double[] xi, int n) {
626
+ Arrays.sort(xi);
627
+ double z[] = StatUtils.normalize(xi);
628
+ NormalDistribution ndist = new NormalDistribution(0, 1);
629
+ double s = 0.0;
630
+
631
+ for(int i = 0; i < n; i++) {
632
+ double fzi = ndist.cumulativeProbability(z[i]);
633
+ double fzni = ndist.cumulativeProbability(z[n - (i + 1)]);
634
+ double logzi = Math.log(fzi);
635
+ double logzni = Math.log(1 - fzni);
636
+
637
+ s += (2.0 * (i + 1.0) - 1.0) * (logzi + logzni);
638
+
639
+ }
640
+ return -1.0 * n - s / n;
641
+ }
642
+ // 補正値の計算(平均未知、分散未知の場合)
643
+ private double calcAD(double a2, int n) {
644
+ return a2 * (1.0 + 0.75 / n + 2.25 / (n * n));
645
+ }
646
+ }
573
647
  }
574
648
 
data/lib/num4normality.rb CHANGED
@@ -22,7 +22,7 @@ module Num4NormalityLib
22
22
  # @note
23
23
  # グラフは、jfreechartを使用
24
24
  def qqplot(dname, xi)
25
- Normality.qqplot(dname, xi.to_java(Java::double))
25
+ Normality.qqPlot(dname, xi.to_java(Java::double))
26
26
  end
27
27
  # コルモゴルフ・スミルノフ検定プロット(1標本)
28
28
  #
@@ -37,7 +37,7 @@ module Num4NormalityLib
37
37
  # @note
38
38
  # グラフは、jfreechartを使用
39
39
  def ksplot(dname, xi)
40
- Normality.ksplot(dname, xi.to_java(Java::double))
40
+ Normality.ksPlot(dname, xi.to_java(Java::double))
41
41
  end
42
42
  # Q-Q and コルモゴルフ・スミルノフ検定プロット(1標本)
43
43
  #
@@ -52,7 +52,7 @@ module Num4NormalityLib
52
52
  # @note
53
53
  # グラフは、jfreechartを使用
54
54
  def qqksplot(dname, xi)
55
- Normality.qqksplot(dname, xi.to_java(Java::double))
55
+ Normality.qqksPlot(dname, xi.to_java(Java::double))
56
56
  end
57
57
  # P-Pプロット
58
58
  #
@@ -67,7 +67,7 @@ module Num4NormalityLib
67
67
  # @note
68
68
  # グラフは、jfreechartを使用
69
69
  def ppplot(dname, xi)
70
- Normality.ppplot(dname, xi.to_java(Java::double))
70
+ Normality.ppPlot(dname, xi.to_java(Java::double))
71
71
  end
72
72
  # P-P and コルモゴルフ・スミルノフ検定プロット(1標本)
73
73
  #
@@ -82,7 +82,7 @@ module Num4NormalityLib
82
82
  # @note
83
83
  # グラフは、jfreechartを使用
84
84
  def ppksplot(dname, xi)
85
- Normality.ppksplot(dname, xi.to_java(Java::double))
85
+ Normality.ppksPlot(dname, xi.to_java(Java::double))
86
86
  end
87
87
  # コルモゴルフ・スミルノフ検定(1標本)
88
88
  #
@@ -94,7 +94,7 @@ module Num4NormalityLib
94
94
  # Num4NormalityLib.kstest(xi)
95
95
  # => false
96
96
  def kstest(xi)
97
- Normality.kstest(xi.to_java(Java::double))
97
+ Normality.ksTest(xi.to_java(Java::double))
98
98
  end
99
99
 
100
100
  # タコスディーノ検定(歪度)
@@ -107,7 +107,7 @@ module Num4NormalityLib
107
107
  # Num4NormalityLib.skewnesstest(xi)
108
108
  # => false
109
109
  def skewnesstest(xi)
110
- Normality.skewnesstest(xi.to_java(Java::double))
110
+ Normality.skewnessTest(xi.to_java(Java::double))
111
111
  end
112
112
  # タコスディーノ検定(尖度)
113
113
  #
@@ -119,7 +119,7 @@ module Num4NormalityLib
119
119
  # Num4NormalityLib.kurtosistest(xi)
120
120
  # => false
121
121
  def kurtosistest(xi)
122
- Normality.kurtosistest(xi.to_java(Java::double))
122
+ Normality.kurtosisTest(xi.to_java(Java::double))
123
123
  end
124
124
  # オムニバス検定
125
125
  #
@@ -131,7 +131,19 @@ module Num4NormalityLib
131
131
  # Num4NormalityLib.omnibustest(xi)
132
132
  # => false
133
133
  def omnibustest(xi)
134
- Normality.omnibustest(xi.to_java(Java::double))
134
+ Normality.omnibusTest(xi.to_java(Java::double))
135
+ end
136
+ # Anderson-darling検定
137
+ #
138
+ # @overload adtest(xi)
139
+ # @param [Array] xi データ(double[])
140
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
141
+ # @example
142
+ # xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
143
+ # Num4NormalityLib.adtest(xi)
144
+ # => false
145
+ def adtest(xi)
146
+ Normality.adTest(xi.to_java(Java::double))
135
147
  end
136
148
  end
137
149
  end
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.8
4
+ version: 0.0.9
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-30 00:00:00.000000000 Z
11
+ date: 2024-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake