num4anova 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 +5 -0
- data/ext/num4anova/MultiComp.java +143 -1
- data/lib/dunnet.rb +89 -0
- data/lib/multicomp.rb +7 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f91d9c210bb998f14a726f1c7147470cba19fba721724625b7ec87e4c88ad9
|
4
|
+
data.tar.gz: a79f6e3ca4adc650193065ae62037cfed0580e5f7b9c5e1d06109d74f17a05d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a1409dfb791766292e8d6c0a49502555911529632d45b72aa6c68bc6fda7e82ed813fff4c005c9c76745a2ad05fe79d1131e23879da18afcc88d0652617c29
|
7
|
+
data.tar.gz: 4cd28879971daf44d20ff8122120327e8a74519f658a22e052724af316387c057cfb315a6d1cb23324bbd08634c066c1045594d6c8804f1f87e12d31b6acd0fb
|
data/CHANGELOG.md
CHANGED
@@ -23,6 +23,28 @@ public class MultiComp {
|
|
23
23
|
double[][] statistic = hypoth.calcTestStatistic(xi);
|
24
24
|
return hypoth.executeTest(statistic, a * 0.5);
|
25
25
|
}
|
26
|
+
public boolean scheffe_test(double[][] xi, double a) {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
|
30
|
+
public boolean[][] twosideTest(double[][] xi, double a) {
|
31
|
+
HypothesisTest hypoth = new TwoSideTest();
|
32
|
+
double[][] statistic = hypoth.calcTestStatistic(xi);
|
33
|
+
|
34
|
+
return hypoth.executeTest(statistic, a / 2.0);
|
35
|
+
}
|
36
|
+
public boolean[][] rightsideTest(double[][] xi, double a) {
|
37
|
+
HypothesisTest hypoth = new RightSideTest();
|
38
|
+
double[][] statistic = hypoth.calcTestStatistic(xi);
|
39
|
+
|
40
|
+
return hypoth.executeTest(statistic, a);
|
41
|
+
}
|
42
|
+
public boolean[][] leftsideTest(double[][] xi, double a) {
|
43
|
+
HypothesisTest hypoth = new LeftSideTest();
|
44
|
+
double[][] statistic = hypoth.calcTestStatistic(xi);
|
45
|
+
|
46
|
+
return hypoth.executeTest(statistic, a);
|
47
|
+
}
|
26
48
|
/*********************************/
|
27
49
|
/* interface define */
|
28
50
|
/*********************************/
|
@@ -145,7 +167,6 @@ public class MultiComp {
|
|
145
167
|
TDistribution tDist = new TDistribution(v);
|
146
168
|
double t =
|
147
169
|
tDist.inverseCumulativeProbability(p);
|
148
|
-
|
149
170
|
return Math.sqrt(2) * t;
|
150
171
|
}
|
151
172
|
}
|
@@ -220,6 +241,127 @@ public class MultiComp {
|
|
220
241
|
return sumSq / na;
|
221
242
|
}
|
222
243
|
}
|
244
|
+
// ダネット法
|
245
|
+
private class DunnetTest{
|
246
|
+
private int k = 0;
|
247
|
+
private int v = 0;
|
248
|
+
private double[] mean = null;
|
249
|
+
private double[] n = null;
|
250
|
+
protected int getK() { return k;}
|
251
|
+
protected int getV() { return v;}
|
252
|
+
public double[][] calcTestStatistic(double[][] xi) {
|
253
|
+
k = xi.length;
|
254
|
+
mean = new double[k];
|
255
|
+
n = new double[k];
|
256
|
+
double[][] statistic = new double[k][k];
|
257
|
+
double ve = calcVe(xi);
|
258
|
+
|
259
|
+
for(int i = 0; i < k; i++) {
|
260
|
+
for(int j = 0; j < k; j++) {
|
261
|
+
statistic[i][j] = (mean[j] - mean[i])
|
262
|
+
/ Math.sqrt(ve * (1.0 / n[j] + 1.0 / n[i]));
|
263
|
+
}
|
264
|
+
}
|
265
|
+
return statistic;
|
266
|
+
}
|
267
|
+
private double calcVe(double[][] xi) {
|
268
|
+
double sumSq = 0.0;
|
269
|
+
int sumN = 0;
|
270
|
+
for(int i = 0; i < k; i++) {
|
271
|
+
DescriptiveStatistics stat = new DescriptiveStatistics();
|
272
|
+
Arrays.stream(xi[i]).forEach(stat::addValue);
|
273
|
+
mean[i] = stat.getMean();
|
274
|
+
n[i] = stat.getN();
|
275
|
+
sumSq += (n[i] - 1) * stat.getVariance();
|
276
|
+
sumN += n[i];
|
277
|
+
stat.clear();
|
278
|
+
}
|
279
|
+
v = sumN - k;
|
280
|
+
return sumSq / v;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
private class TwoSideTest extends DunnetTest
|
284
|
+
implements HypothesisTest {
|
285
|
+
public boolean[][] executeTest(double[][] statistic, double a) {
|
286
|
+
int v = super.getV();
|
287
|
+
int k = super.getK();
|
288
|
+
double den = k - 1;
|
289
|
+
double p = 1.0 - a / den;
|
290
|
+
TDistribution tDist = new TDistribution(v);
|
291
|
+
double l_val = tDist.inverseCumulativeProbability(a / den);
|
292
|
+
double r_val = tDist.inverseCumulativeProbability(1.0 - a / den);
|
293
|
+
boolean[][] ret = new boolean[k][k];
|
294
|
+
|
295
|
+
for(int i = 0; i < k; i++) {
|
296
|
+
for(int j = 0; j < k; j++) {
|
297
|
+
ret[i][j] = evaluation(statistic[i][j], l_val, r_val );
|
298
|
+
}
|
299
|
+
}
|
300
|
+
return ret;
|
301
|
+
}
|
302
|
+
private boolean evaluation(double statistic, double l_val, double r_val) {
|
303
|
+
boolean ret = true;
|
304
|
+
|
305
|
+
if ((l_val < statistic) && (statistic < r_val)) {
|
306
|
+
ret = false;
|
307
|
+
}
|
308
|
+
return ret;
|
309
|
+
}
|
310
|
+
}
|
311
|
+
private class RightSideTest extends DunnetTest
|
312
|
+
implements HypothesisTest {
|
313
|
+
public boolean[][] executeTest(double[][] statistic, double a) {
|
314
|
+
int v = super.getV();
|
315
|
+
int k = super.getK();
|
316
|
+
double den = k - 1;
|
317
|
+
double p = 1.0 - a / den;
|
318
|
+
TDistribution tDist = new TDistribution(v);
|
319
|
+
double r_val = tDist.inverseCumulativeProbability(1.0 - a);
|
320
|
+
boolean[][] ret = new boolean[k][k];
|
321
|
+
|
322
|
+
for(int i = 0; i < k; i++) {
|
323
|
+
for(int j = 0; j < k; j++) {
|
324
|
+
ret[i][j] = evaluation(statistic[i][j], r_val );
|
325
|
+
}
|
326
|
+
}
|
327
|
+
return ret;
|
328
|
+
}
|
329
|
+
private boolean evaluation(double statistic, double r_val) {
|
330
|
+
boolean ret = true;
|
331
|
+
|
332
|
+
if (statistic < r_val) {
|
333
|
+
ret = false;
|
334
|
+
}
|
335
|
+
return ret;
|
336
|
+
}
|
337
|
+
}
|
338
|
+
private class LeftSideTest extends DunnetTest
|
339
|
+
implements HypothesisTest {
|
340
|
+
public boolean[][] executeTest(double[][] statistic, double a) {
|
341
|
+
int v = super.getV();
|
342
|
+
int k = super.getK();
|
343
|
+
double den = k - 1;
|
344
|
+
double p = a / den;
|
345
|
+
TDistribution tDist = new TDistribution(v);
|
346
|
+
double l_val = tDist.inverseCumulativeProbability(a);
|
347
|
+
boolean[][] ret = new boolean[k][k];
|
348
|
+
|
349
|
+
for(int i = 0; i < k; i++) {
|
350
|
+
for(int j = 0; j < k; j++) {
|
351
|
+
ret[i][j] = evaluation(statistic[i][j], l_val );
|
352
|
+
}
|
353
|
+
}
|
354
|
+
return ret;
|
355
|
+
}
|
356
|
+
private boolean evaluation(double statistic, double l_val) {
|
357
|
+
boolean ret = true;
|
358
|
+
|
359
|
+
if (l_val < statistic) {
|
360
|
+
ret = false;
|
361
|
+
}
|
362
|
+
return ret;
|
363
|
+
}
|
364
|
+
}
|
223
365
|
}
|
224
366
|
}
|
225
367
|
|
data/lib/dunnet.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Dunnet検定
|
2
|
+
# (Apache commoms math3使用)
|
3
|
+
module DunnetTestLib
|
4
|
+
# Dunnet検定の両側検定
|
5
|
+
#
|
6
|
+
# @overload twoside_test(xi, a)
|
7
|
+
# @param [array] xi データ(double[][])
|
8
|
+
# @param [double] a 有意水準
|
9
|
+
# @return [Array] 検定結果(boolean[][] true:棄却域内 false:棄却域外)
|
10
|
+
# @example
|
11
|
+
# xi = [
|
12
|
+
# [12.2, 18.8, 18.2],
|
13
|
+
# [22.2, 20.5, 14.6],
|
14
|
+
# [20.8, 19.5, 26.3],
|
15
|
+
# [26.4, 32.5, 31.3],
|
16
|
+
# [24.5, 21.2, 22.4],
|
17
|
+
# ]
|
18
|
+
# paraTest = MultiCompLib::ParametrixTestLib.new
|
19
|
+
# paraTest.twoside_test(xi, 0.05)
|
20
|
+
# =>
|
21
|
+
# res = [
|
22
|
+
# [false, false, false, true, false],
|
23
|
+
# [false, false, false, true, false],
|
24
|
+
# [false, false, false, false, false],
|
25
|
+
# [true, true, false, false, false],
|
26
|
+
# [false, false, false, false, false],
|
27
|
+
# ]
|
28
|
+
def twoside_test(xi, a)
|
29
|
+
ret = @paramTest.twosideTest(xi.to_java(Java::double[]), a)
|
30
|
+
return ret.to_a
|
31
|
+
end
|
32
|
+
# Dunnet検定の右側検定
|
33
|
+
#
|
34
|
+
# @overload rightside_test(xi, a)
|
35
|
+
# @param [array] xi データ(double[][])
|
36
|
+
# @param [double] a 有意水準
|
37
|
+
# @return [Array] 検定結果(boolean[][] true:棄却域内 false:棄却域外)
|
38
|
+
# @example
|
39
|
+
# xi = [
|
40
|
+
# [12.2, 18.8, 18.2],
|
41
|
+
# [22.2, 20.5, 14.6],
|
42
|
+
# [20.8, 19.5, 26.3],
|
43
|
+
# [26.4, 32.5, 31.3],
|
44
|
+
# [24.5, 21.2, 22.4],
|
45
|
+
# ]
|
46
|
+
# paraTest = MultiCompLib::ParametrixTestLib.new
|
47
|
+
# paraTest.rightside_test(xi, 0.05)
|
48
|
+
# =>
|
49
|
+
# res = [
|
50
|
+
# [false, false, true, true, true],
|
51
|
+
# [false, false, false, true, false],
|
52
|
+
# [false, false, false, true, false],
|
53
|
+
# [false, false, false, false, false],
|
54
|
+
# [false, false, false, true, false],
|
55
|
+
# ]
|
56
|
+
def rightside_test(xi, a)
|
57
|
+
ret = @paramTest.rightsideTest(xi.to_java(Java::double[]), a)
|
58
|
+
return ret.to_a
|
59
|
+
end
|
60
|
+
# Dunnet検定の左側検定
|
61
|
+
#
|
62
|
+
# @overload leftside_test(xi, a)
|
63
|
+
# @param [array] xi データ(double[][])
|
64
|
+
# @param [double] a 有意水準
|
65
|
+
# @return [Array] 検定結果(boolean[][] true:棄却域内 false:棄却域外)
|
66
|
+
# @example
|
67
|
+
# xi = [
|
68
|
+
# [12.2, 18.8, 18.2],
|
69
|
+
# [22.2, 20.5, 14.6],
|
70
|
+
# [20.8, 19.5, 26.3],
|
71
|
+
# [26.4, 32.5, 31.3],
|
72
|
+
# [24.5, 21.2, 22.4],
|
73
|
+
# ]
|
74
|
+
# paraTest = MultiCompLib::ParametrixTestLib.new
|
75
|
+
# paraTest.leftside_test(xi, 0.05)
|
76
|
+
# =>
|
77
|
+
# res = [
|
78
|
+
# [false, false, false, false, false],
|
79
|
+
# [false, false, false, false, false],
|
80
|
+
# [true, false, false, false, false],
|
81
|
+
# [true, true, true, false, true],
|
82
|
+
# [true, false, false, false, false],
|
83
|
+
# ]
|
84
|
+
def leftside_test(xi, a)
|
85
|
+
ret = @paramTest.leftsideTest(xi.to_java(Java::double[]), a)
|
86
|
+
return ret.to_a
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
data/lib/multicomp.rb
CHANGED
@@ -3,12 +3,15 @@ require 'num4anova.jar'
|
|
3
3
|
require 'jfreechart-1.5.4.jar'
|
4
4
|
require 'commons-math3-3.6.1.jar'
|
5
5
|
|
6
|
+
require_relative('dunnet')
|
7
|
+
|
6
8
|
java_import 'MultiComp'
|
7
9
|
# 多重比較を行う
|
8
10
|
# (Apache commoms math3使用)
|
9
11
|
module MultiCompLib
|
10
12
|
# パラメトリック検定
|
11
13
|
class ParametrixTestLib
|
14
|
+
include DunnetTestLib
|
12
15
|
def initialize
|
13
16
|
@paramTest = MultiComp::ParametrixTest.getInstance()
|
14
17
|
end
|
@@ -26,7 +29,8 @@ module MultiCompLib
|
|
26
29
|
# [26.4, 32.5, 31.3],
|
27
30
|
# [24.5, 21.2, 22.4],
|
28
31
|
# ]
|
29
|
-
# paraTest.
|
32
|
+
# paraTest = MultiCompLib::ParametrixTestLib.new
|
33
|
+
# paraTest.turkey_test(xi, 0.05)
|
30
34
|
# =>
|
31
35
|
# [
|
32
36
|
# [false, false, false, true, false],
|
@@ -53,7 +57,8 @@ module MultiCompLib
|
|
53
57
|
# [26.4, 32.5, 31.3],
|
54
58
|
# [24.5, 21.2, 22.4],
|
55
59
|
# ]
|
56
|
-
# paraTest.
|
60
|
+
# paraTest = MultiCompLib::ParametrixTestLib.new
|
61
|
+
# paraTest.bonferrono_test(xi, 0.05)
|
57
62
|
# =>
|
58
63
|
# [
|
59
64
|
# [false, false, false, true, false],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: num4anova
|
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: 2024-01-
|
11
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ext/num4anova/MultiComp.java
|
65
65
|
- ext/num4anova/OneWayLayout.java
|
66
66
|
- lib/commons-math3-3.6.1.jar
|
67
|
+
- lib/dunnet.rb
|
67
68
|
- lib/jcommon-1.0.23.jar
|
68
69
|
- lib/jfreechart-1.5.4.jar
|
69
70
|
- lib/multicomp.rb
|