num4normality 0.0.8-java → 0.0.10-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 +4 -4
- data/CHANGELOG.md +8 -0
- data/ext/num4normality/Normality.java +130 -28
- data/lib/num4normality.rb +33 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc5dd36e009ab6ce0b3a044652184f723ce70b416bab8780d01a56952bcd7b8b
|
4
|
+
data.tar.gz: 46fa3aefe151fb4e6dd8a47a3c4a4e38670704dd74b21a9d6fb19f6a13349a82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9933cc4c22ac645b17ae8e65b835d72fc80453e05c478903d1c748d3ff66615b9a0c631ced2ef4a2c8051297b2da16cdcd73b47d654032ed79599b0ae19f2bf
|
7
|
+
data.tar.gz: c74c186cc3caa4d511f8187ec9b7024d85ae8249d40692942800655c45fda60589be35745cb94659fd7d40038e65d4a0e3cb4ae91ef837d06302a6e180736e6d
|
data/CHANGELOG.md
CHANGED
@@ -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,80 @@ 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
|
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
|
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
|
48
|
-
|
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
|
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
|
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
|
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
|
72
|
-
|
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,
|
77
|
+
return daigo.test(b1, HypothesisTest.P);
|
76
78
|
}
|
77
|
-
public static boolean
|
78
|
-
|
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,
|
83
|
+
return daigo.test(b2, HypothesisTest.P);
|
82
84
|
}
|
83
|
-
public static boolean
|
84
|
-
|
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,
|
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);
|
96
|
+
}
|
97
|
+
public static boolean jbTest(double[] xi) {
|
98
|
+
HypothesisTest daigo = new JBTest();
|
99
|
+
double x = daigo.calcTestStatistic(xi);
|
100
|
+
|
101
|
+
return daigo.test(x, HypothesisTest.P);
|
88
102
|
}
|
89
|
-
|
90
103
|
/*********************************/
|
91
104
|
/* interface define */
|
92
105
|
/*********************************/
|
@@ -108,7 +121,11 @@ public class Normality {
|
|
108
121
|
private interface CreatePlot {
|
109
122
|
XYPlot createPlot(String dname, double[] xi);
|
110
123
|
}
|
111
|
-
private interface
|
124
|
+
private interface HypothesisTest {
|
125
|
+
/* フィールド */
|
126
|
+
static final double P = 0.05;
|
127
|
+
|
128
|
+
/* メゾット */
|
112
129
|
double calcTestStatistic(double[] xi);
|
113
130
|
boolean test(double statistic, double a);
|
114
131
|
}
|
@@ -121,7 +138,10 @@ public class Normality {
|
|
121
138
|
XYPlot plot = createPlot(dname, xi);
|
122
139
|
|
123
140
|
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
|
124
|
-
|
141
|
+
JFreeChart chart = new JFreeChart(title, plot);
|
142
|
+
|
143
|
+
ChartUtils.applyCurrentTheme(chart);
|
144
|
+
return chart;
|
125
145
|
}
|
126
146
|
private XYPlot createPlot(String dname, double[] xi) {
|
127
147
|
CreatePlot plotImpl = new QQPlot();
|
@@ -224,7 +244,10 @@ public class Normality {
|
|
224
244
|
XYPlot plot = createPlot(dname, xi);
|
225
245
|
|
226
246
|
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
|
227
|
-
|
247
|
+
JFreeChart chart = new JFreeChart(title, plot);
|
248
|
+
|
249
|
+
ChartUtils.applyCurrentTheme(chart);
|
250
|
+
return chart;
|
228
251
|
}
|
229
252
|
private XYPlot createPlot(String dname, double[] xi) {
|
230
253
|
CreatePlot plotImpl = new KSPlot();
|
@@ -326,7 +349,10 @@ public class Normality {
|
|
326
349
|
XYPlot plot = createPlot(dname, xi);
|
327
350
|
|
328
351
|
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
|
329
|
-
|
352
|
+
JFreeChart chart = new JFreeChart(title, plot);
|
353
|
+
|
354
|
+
ChartUtils.applyCurrentTheme(chart);
|
355
|
+
return chart;
|
330
356
|
}
|
331
357
|
private XYPlot createPlot(String dname, double[] xi) {
|
332
358
|
/*--- 横軸 ---*/
|
@@ -351,7 +377,10 @@ public class Normality {
|
|
351
377
|
XYPlot plot = createPlot(dname, xi);
|
352
378
|
|
353
379
|
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
|
354
|
-
|
380
|
+
JFreeChart chart = new JFreeChart(title, plot);
|
381
|
+
|
382
|
+
ChartUtils.applyCurrentTheme(chart);
|
383
|
+
return chart;
|
355
384
|
}
|
356
385
|
private XYPlot createPlot(String dname, double[] xi) {
|
357
386
|
CreatePlot plotImpl = new PPPlot();
|
@@ -460,7 +489,10 @@ public class Normality {
|
|
460
489
|
XYPlot plot = createPlot(dname, xi);
|
461
490
|
|
462
491
|
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
|
463
|
-
|
492
|
+
JFreeChart chart = new JFreeChart(title, plot);
|
493
|
+
|
494
|
+
ChartUtils.applyCurrentTheme(chart);
|
495
|
+
return chart;
|
464
496
|
}
|
465
497
|
private XYPlot createPlot(String dname, double[] xi) {
|
466
498
|
/*--- 縦軸 ---*/
|
@@ -490,7 +522,7 @@ public class Normality {
|
|
490
522
|
}
|
491
523
|
}
|
492
524
|
// タコスディーノ検定(歪度)
|
493
|
-
private static class SkewnessTest implements
|
525
|
+
private static class SkewnessTest implements HypothesisTest {
|
494
526
|
private long n = 0;
|
495
527
|
private NormalDistribution ndist = null;
|
496
528
|
public SkewnessTest() {
|
@@ -520,7 +552,7 @@ public class Normality {
|
|
520
552
|
}
|
521
553
|
}
|
522
554
|
// タコスディーノ検定(尖度)
|
523
|
-
private static class KurtosisTest implements
|
555
|
+
private static class KurtosisTest implements HypothesisTest {
|
524
556
|
private long n = 0;
|
525
557
|
private NormalDistribution ndist = null;
|
526
558
|
public KurtosisTest() {
|
@@ -550,9 +582,9 @@ public class Normality {
|
|
550
582
|
}
|
551
583
|
}
|
552
584
|
// オムニバス検定
|
553
|
-
private static class OmnibusTest implements
|
554
|
-
private
|
555
|
-
private
|
585
|
+
private static class OmnibusTest implements HypothesisTest {
|
586
|
+
private HypothesisTest skewness = null;
|
587
|
+
private HypothesisTest kurtosis = null;
|
556
588
|
public OmnibusTest() {
|
557
589
|
skewness = new SkewnessTest();
|
558
590
|
kurtosis = new KurtosisTest();
|
@@ -567,6 +599,76 @@ public class Normality {
|
|
567
599
|
ChiSquaredDistribution chi2Dist = new ChiSquaredDistribution(2);
|
568
600
|
double p = chi2Dist.cumulativeProbability(statistic);
|
569
601
|
|
602
|
+
return (p < a) ? true : false;
|
603
|
+
}
|
604
|
+
}
|
605
|
+
// Anderson-Darling検定
|
606
|
+
private static class ADTest implements HypothesisTest {
|
607
|
+
public double calcTestStatistic(double[] xi) {
|
608
|
+
int n = xi.length;
|
609
|
+
double a2 = calcA2(xi, n);
|
610
|
+
|
611
|
+
return calcAD(a2, n);
|
612
|
+
}
|
613
|
+
public boolean test(double statistic, double a) {
|
614
|
+
double p = 0.0;
|
615
|
+
double statistic2 = statistic * statistic;
|
616
|
+
|
617
|
+
if (statistic <= 0.2) {
|
618
|
+
p = 1.0 - Math.exp(-13.436 + 101.14 * statistic - 223.73 * statistic);
|
619
|
+
}
|
620
|
+
else if ((0.2 < statistic) && (statistic <= 0.34)) {
|
621
|
+
p = 1.0 - Math.exp(-8.318 + 42.796 * statistic - 59.938 * statistic2);
|
622
|
+
}
|
623
|
+
else if ((0.34 < statistic) && (statistic <= 0.6)) {
|
624
|
+
p = Math.exp(0.9177 - 4.279 * statistic - 1.38 * statistic2);
|
625
|
+
}
|
626
|
+
else {
|
627
|
+
p = Math.exp(1.2937 - 5.709 * statistic + 0.0186 * statistic2);
|
628
|
+
}
|
629
|
+
return (p <= a) ? true : false;
|
630
|
+
}
|
631
|
+
private double calcA2(double[] xi, int n) {
|
632
|
+
Arrays.sort(xi);
|
633
|
+
double z[] = StatUtils.normalize(xi);
|
634
|
+
NormalDistribution ndist = new NormalDistribution(0, 1);
|
635
|
+
double s = 0.0;
|
636
|
+
|
637
|
+
for(int i = 0; i < n; i++) {
|
638
|
+
double fzi = ndist.cumulativeProbability(z[i]);
|
639
|
+
double fzni = ndist.cumulativeProbability(z[n - (i + 1)]);
|
640
|
+
double logzi = Math.log(fzi);
|
641
|
+
double logzni = Math.log(1 - fzni);
|
642
|
+
|
643
|
+
s += (2.0 * (i + 1.0) - 1.0) * (logzi + logzni);
|
644
|
+
|
645
|
+
}
|
646
|
+
return -1.0 * n - s / n;
|
647
|
+
}
|
648
|
+
// 補正値の計算(平均未知、分散未知の場合)
|
649
|
+
private double calcAD(double a2, int n) {
|
650
|
+
return a2 * (1.0 + 0.75 / n + 2.25 / (n * n));
|
651
|
+
}
|
652
|
+
}
|
653
|
+
// Jarque-Bera検定
|
654
|
+
private static class JBTest implements HypothesisTest {
|
655
|
+
private HypothesisTest skewness = null;
|
656
|
+
private HypothesisTest kurtosis = null;
|
657
|
+
public JBTest() {
|
658
|
+
skewness = new SkewnessTest();
|
659
|
+
kurtosis = new KurtosisTest();
|
660
|
+
}
|
661
|
+
public double calcTestStatistic(double[] xi) {
|
662
|
+
int n = xi.length;
|
663
|
+
double x1 = skewness.calcTestStatistic(xi);
|
664
|
+
double x2 = kurtosis.calcTestStatistic(xi);
|
665
|
+
|
666
|
+
return n / 6.0 * (x1 *x1 + x2 * x2 / 4.0);
|
667
|
+
}
|
668
|
+
public boolean test(double statistic, double a) {
|
669
|
+
ChiSquaredDistribution chi2Dist = new ChiSquaredDistribution(2);
|
670
|
+
double p = chi2Dist.cumulativeProbability(statistic);
|
671
|
+
|
570
672
|
return (p < a) ? true : false;
|
571
673
|
}
|
572
674
|
}
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
122
|
+
Normality.kurtosisTest(xi.to_java(Java::double))
|
123
123
|
end
|
124
124
|
# オムニバス検定
|
125
125
|
#
|
@@ -131,7 +131,31 @@ module Num4NormalityLib
|
|
131
131
|
# Num4NormalityLib.omnibustest(xi)
|
132
132
|
# => false
|
133
133
|
def omnibustest(xi)
|
134
|
-
Normality.
|
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))
|
147
|
+
end
|
148
|
+
# Jarque-Bera検定
|
149
|
+
#
|
150
|
+
# @overload jbtest(xi)
|
151
|
+
# @param [Array] xi データ(double[])
|
152
|
+
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
153
|
+
# @example
|
154
|
+
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
|
155
|
+
# Num4NormalityLib.jbtest(xi)
|
156
|
+
# => false
|
157
|
+
def jbtest(xi)
|
158
|
+
Normality.jbTest(xi.to_java(Java::double))
|
135
159
|
end
|
136
160
|
end
|
137
161
|
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.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- siranovel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|