num4normality 0.0.2-java → 0.0.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/ext/num4normality/Normality.java +40 -17
- data/lib/num4normality.rb +23 -10
- 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: a735c6ff8848bf8f8c56b7e1bc0b1794a5675ab93d3e9a13477cf8d3041b50d9
|
4
|
+
data.tar.gz: 87b102e787cd5835ce2c78ebf11e0abf8a2092462cbf9ff7fd73e06a3884d43b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c808547090cef242d28bbfbc46243fc44726a69d22c18a03916f76ccb7e91b58b7c3a074f1fe7fd7a17c492da9978197358db941c20c1255fcd90773cc28e54d
|
7
|
+
data.tar.gz: ff78669f413ae51fae98f4fb683981b12793f2a93eaeb17438124e1ad3771b476a34955e4482bc669bcd4044ec31a95f08e9c0c93b89a802b03fe7d664d03c4c
|
data/CHANGELOG.md
CHANGED
@@ -24,6 +24,8 @@ import org.apache.commons.math3.distribution.NormalDistribution;
|
|
24
24
|
import org.apache.commons.math3.stat.regression.SimpleRegression;
|
25
25
|
import java.util.Arrays;
|
26
26
|
import java.text.DecimalFormat;
|
27
|
+
|
28
|
+
import org.apache.commons.math3.stat.inference.TestUtils;
|
27
29
|
public class Normality {
|
28
30
|
public static void qqplot(String dname, double[] xi) {
|
29
31
|
ChartPlot plot = new QQPlot();
|
@@ -31,13 +33,18 @@ public class Normality {
|
|
31
33
|
|
32
34
|
plot.writeJPEG("qqplot.jpeg", chart, 800, 500);
|
33
35
|
}
|
34
|
-
public static void
|
35
|
-
ChartPlot plot = new
|
36
|
+
public static void ksplot(String dname, double[] xi) {
|
37
|
+
ChartPlot plot = new KSPlot();
|
36
38
|
JFreeChart chart = plot.createChart(dname, xi);
|
37
39
|
|
38
|
-
plot.writeJPEG("
|
40
|
+
plot.writeJPEG("ksplot.jpeg", chart, 800, 500);
|
39
41
|
|
40
42
|
}
|
43
|
+
public static boolean kstest(double[] xi) {
|
44
|
+
KSTest ks = new KSTest();
|
45
|
+
|
46
|
+
return ks.test(xi);
|
47
|
+
}
|
41
48
|
public static boolean skewnesstest(double[] xi) {
|
42
49
|
DAgostinosTest daigo = new SkewnessTest();
|
43
50
|
|
@@ -53,6 +60,10 @@ public class Normality {
|
|
53
60
|
|
54
61
|
|
55
62
|
private interface ChartPlot {
|
63
|
+
/* フィールド */
|
64
|
+
static final double CLASS_MIN = -4.0;
|
65
|
+
static final double CLASS_MAX = 4.0;
|
66
|
+
/* メゾット */
|
56
67
|
JFreeChart createChart(String dname, double[] xi);
|
57
68
|
default void writeJPEG(String fname, JFreeChart chart, int width, int height) {
|
58
69
|
File file = new File(fname);
|
@@ -104,8 +115,8 @@ public class Normality {
|
|
104
115
|
plot.setDomainAxis(domainAxis);
|
105
116
|
domainAxis.setLowerMargin(0.03);
|
106
117
|
domainAxis.setUpperMargin(0.03);
|
107
|
-
domainAxis.setLowerBound(
|
108
|
-
domainAxis.setUpperBound(
|
118
|
+
domainAxis.setLowerBound(ChartPlot.CLASS_MIN);
|
119
|
+
domainAxis.setUpperBound(ChartPlot.CLASS_MAX);
|
109
120
|
|
110
121
|
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
|
111
122
|
return new JFreeChart("正規性の検定", plot);
|
@@ -157,7 +168,7 @@ public class Normality {
|
|
157
168
|
double a = simpleReg.getSlope();
|
158
169
|
double b = simpleReg.getIntercept();
|
159
170
|
|
160
|
-
for (double x =
|
171
|
+
for (double x = ChartPlot.CLASS_MIN; x < ChartPlot.CLASS_MAX; x += 0.01) {
|
161
172
|
double y = a * x + b;
|
162
173
|
|
163
174
|
cu.add(x, y);
|
@@ -168,11 +179,7 @@ public class Normality {
|
|
168
179
|
}
|
169
180
|
}
|
170
181
|
// コルモゴルフ・スミルノフ検定
|
171
|
-
private static class
|
172
|
-
private NormalDistribution ndist = null;
|
173
|
-
public KSTest() {
|
174
|
-
ndist = new NormalDistribution(0, 1);
|
175
|
-
}
|
182
|
+
private static class KSPlot implements ChartPlot {
|
176
183
|
public JFreeChart createChart(String dname, double[] xi) {
|
177
184
|
NumberAxis domainAxis = new NumberAxis("標準正規分布");
|
178
185
|
XYPlot plot = createPlot(dname, xi);
|
@@ -230,13 +237,11 @@ public class Normality {
|
|
230
237
|
double p = 0.0;
|
231
238
|
|
232
239
|
XYSeries cu = new XYSeries(dname);
|
233
|
-
for (int i = 0; i <
|
240
|
+
for (int i = 0; i < n; i++) {
|
234
241
|
double x = (xi[i] - m) / sd;
|
242
|
+
|
235
243
|
p += xi[i] / sum;
|
236
|
-
|
237
|
-
ndist.inverseCumulativeProbability((i + 1.0) / (n + 1.0));
|
238
|
-
|
239
|
-
cu.add(Math.min(x, y), p);
|
244
|
+
cu.add(x, p);
|
240
245
|
}
|
241
246
|
XYSeriesCollection series = new XYSeriesCollection();
|
242
247
|
|
@@ -244,7 +249,8 @@ public class Normality {
|
|
244
249
|
return series;
|
245
250
|
}
|
246
251
|
private XYSeriesCollection createDataset1() {
|
247
|
-
|
252
|
+
NormalDistribution ndist = new NormalDistribution(0, 1);
|
253
|
+
XYSeries cu = new XYSeries("累積p");
|
248
254
|
|
249
255
|
for (double x = -4; x < 4; x += 0.01) {
|
250
256
|
double y = ndist.cumulativeProbability(x);
|
@@ -257,6 +263,23 @@ public class Normality {
|
|
257
263
|
return series;
|
258
264
|
}
|
259
265
|
}
|
266
|
+
private static class KSTest {
|
267
|
+
public boolean test(double[] xi) {
|
268
|
+
double[] data = new double[xi.length];
|
269
|
+
Arrays.sort(xi);
|
270
|
+
DescriptiveStatistics stat = new DescriptiveStatistics();
|
271
|
+
Arrays.stream(xi).forEach(stat::addValue);
|
272
|
+
double m = stat.getMean(); // 平均
|
273
|
+
double sd = stat.getStandardDeviation();// 標準偏差
|
274
|
+
NormalDistribution ndist = new NormalDistribution(0, 1);
|
275
|
+
|
276
|
+
for (int i = 0; i < xi.length; i++) {
|
277
|
+
data[i] = (xi[i] - m) / sd;
|
278
|
+
}
|
279
|
+
boolean ret = TestUtils.kolmogorovSmirnovTest(ndist, data, 0.05);
|
280
|
+
return ret;
|
281
|
+
}
|
282
|
+
}
|
260
283
|
// タコスディーノ検定(歪度)
|
261
284
|
private static class SkewnessTest implements DAgostinosTest {
|
262
285
|
private long n = 0;
|
data/lib/num4normality.rb
CHANGED
@@ -16,7 +16,7 @@ module Num4NormalityLib
|
|
16
16
|
# @param [Array] xi データ(double[])
|
17
17
|
# @return [void] qqplot.jpegファイルを出力
|
18
18
|
# @example
|
19
|
-
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209]
|
19
|
+
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
|
20
20
|
# Num4NormalityLib.qqplot("LDH", xi)
|
21
21
|
# => qqplot.jpeg
|
22
22
|
# @note
|
@@ -24,28 +24,41 @@ module Num4NormalityLib
|
|
24
24
|
def qqplot(dname, xi)
|
25
25
|
Normality.qqplot(dname, xi.to_java(Java::double))
|
26
26
|
end
|
27
|
-
#
|
27
|
+
# コルモゴルフ・スミルノフ検定プロット(1標本)
|
28
28
|
#
|
29
|
-
# @overload
|
29
|
+
# @overload ksplot(dname, xi)
|
30
30
|
# @param [String] dname データ名
|
31
31
|
# @param [Array] xi データ(double[])
|
32
|
-
# @return [void]
|
32
|
+
# @return [void] ksplot.jpegファイルを出力
|
33
33
|
# @example
|
34
|
-
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209]
|
35
|
-
# Num4NormalityLib.
|
34
|
+
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
|
35
|
+
# Num4NormalityLib.ksplot("LDH", xi)
|
36
36
|
# => kstest.jpeg
|
37
37
|
# @note
|
38
38
|
# グラフは、jfreechartを使用
|
39
|
-
def
|
40
|
-
Normality.
|
39
|
+
def ksplot(dname, xi)
|
40
|
+
Normality.ksplot(dname, xi.to_java(Java::double))
|
41
41
|
end
|
42
|
+
# コルモゴルフ・スミルノフ検定(1標本)
|
43
|
+
#
|
44
|
+
# @overload kstest(xi)
|
45
|
+
# @param [Array] xi データ(double[])
|
46
|
+
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
47
|
+
# @example
|
48
|
+
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
|
49
|
+
# Num4NormalityLib.kstest(xi)
|
50
|
+
# => false
|
51
|
+
def kstest(xi)
|
52
|
+
Normality.kstest(xi.to_java(Java::double))
|
53
|
+
end
|
54
|
+
|
42
55
|
# タコスディーノ検定(歪度)
|
43
56
|
#
|
44
57
|
# @overload skewnesstest(xi)
|
45
58
|
# @param [Array] xi データ(double[])
|
46
59
|
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
47
60
|
# @example
|
48
|
-
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209]
|
61
|
+
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
|
49
62
|
# Num4NormalityLib.skewnesstest(xi)
|
50
63
|
# => false
|
51
64
|
def skewnesstest(xi)
|
@@ -57,7 +70,7 @@ module Num4NormalityLib
|
|
57
70
|
# @param [Array] xi データ(double[])
|
58
71
|
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
59
72
|
# @example
|
60
|
-
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209]
|
73
|
+
# xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
|
61
74
|
# Num4NormalityLib.kurtosistest(xi)
|
62
75
|
# => false
|
63
76
|
def kurtosistest(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
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2023-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|