num4anova 0.0.12-java → 0.0.14-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 +10 -0
- data/ext/num4anova/Ancova.java +13 -8
- data/ext/num4anova/MultiComp.java +58 -7
- data/lib/multicomp.rb +33 -1
- data/lib/num4anova.rb +16 -6
- 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: 844b392125f78a4966a67dd1162bef6676857f03ed9f49e48d4f00e9f294d6e9
|
4
|
+
data.tar.gz: da4999753cf5b2b73336b365c53e79ad5eb084fcb44151fdf6c05b5c691a40d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c8e9884146305d0db99633f36997de0dc3ec4593e2b497fa6f97c1d9cf957721ad233914454e2eb1f8334b86871fdb389f073d62492904432da76415f9a302f
|
7
|
+
data.tar.gz: 79b9cc886c7f2f8b794c204db714ca5663e9b9acb0388eee8afd60cef393b9f107e3f32f05855f848c53e39fc67f42212d352d87c0fdc2262718178f6d36d1d1
|
data/CHANGELOG.md
CHANGED
data/ext/num4anova/Ancova.java
CHANGED
@@ -24,7 +24,7 @@ public class Ancova {
|
|
24
24
|
double statistic = hypoth.calcTestStatistic(xi);
|
25
25
|
return hypoth.executeTest(statistic, a);
|
26
26
|
}
|
27
|
-
public Interval intervalEstim(double[][][] xi, double a) {
|
27
|
+
public Interval[] intervalEstim(double[][][] xi, double a) {
|
28
28
|
Estim estim = new IntervalEstim();
|
29
29
|
|
30
30
|
return estim.calcInterval(xi, a);
|
@@ -37,7 +37,7 @@ public class Ancova {
|
|
37
37
|
boolean executeTest(double statistic, double a);
|
38
38
|
}
|
39
39
|
private interface Estim {
|
40
|
-
Interval calcInterval(double[][][] xi, double a);
|
40
|
+
Interval[] calcInterval(double[][][] xi, double a);
|
41
41
|
}
|
42
42
|
/*********************************/
|
43
43
|
/* class define */
|
@@ -346,7 +346,8 @@ public class Ancova {
|
|
346
346
|
private int n = 0;
|
347
347
|
private int[] ni = null;
|
348
348
|
private double sumex = 0.0;
|
349
|
-
public Interval calcInterval(double[][][] xi, double a) {
|
349
|
+
public Interval[] calcInterval(double[][][] xi, double a) {
|
350
|
+
Interval[] ret = new Interval[xi.length];
|
350
351
|
ni = calcNi(xi);
|
351
352
|
int sumn = calcSumn(xi);
|
352
353
|
n = sumn - xi.length - 1;
|
@@ -360,12 +361,16 @@ public class Ancova {
|
|
360
361
|
|
361
362
|
TDistribution tDist = new TDistribution(n);
|
362
363
|
double t = tDist.inverseCumulativeProbability(1.0 - a / 2.0);
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
364
|
+
for(int i = 0; i < ret.length; i++) {
|
365
|
+
double wk = (meanxi[i] - meanx);
|
366
|
+
double wk2 = t * Math.sqrt((1/ni[i] + wk * wk / sumex) * ve);
|
367
|
+
double min = meanyi[i] - b * wk - wk2;
|
368
|
+
double max = meanyi[i] - b * wk + wk2;
|
367
369
|
|
368
|
-
|
370
|
+
ret[i] = new Interval(min, max);
|
371
|
+
}
|
372
|
+
|
373
|
+
return ret;
|
369
374
|
}
|
370
375
|
private int[] calcNi(double[][][] xi) {
|
371
376
|
int[] ni = new int[xi.length];
|
@@ -3,9 +3,17 @@ import java.util.Arrays;
|
|
3
3
|
import java.util.List;
|
4
4
|
import java.util.ArrayList;
|
5
5
|
import org.apache.commons.math3.distribution.TDistribution;
|
6
|
+
import org.apache.commons.math3.stat.inference.MannWhitneyUTest;
|
6
7
|
|
7
8
|
import org.apache.commons.math3.util.Combinations;
|
8
9
|
public class MultiComp {
|
10
|
+
/*********************************/
|
11
|
+
/* interface define */
|
12
|
+
/*********************************/
|
13
|
+
private interface HypothesisTest {
|
14
|
+
double[][] calcTestStatistic(double[][] xi);
|
15
|
+
boolean[][] executeTest(double[][] statistic, double a);
|
16
|
+
}
|
9
17
|
public static class ParametrixTest {
|
10
18
|
private static ParametrixTest paramTest = new ParametrixTest();
|
11
19
|
public static ParametrixTest getInstance() {
|
@@ -46,13 +54,6 @@ public class MultiComp {
|
|
46
54
|
return hypoth.executeTest(statistic, a);
|
47
55
|
}
|
48
56
|
/*********************************/
|
49
|
-
/* interface define */
|
50
|
-
/*********************************/
|
51
|
-
private interface HypothesisTest {
|
52
|
-
double[][] calcTestStatistic(double[][] xi);
|
53
|
-
boolean[][] executeTest(double[][] statistic, double a);
|
54
|
-
}
|
55
|
-
/*********************************/
|
56
57
|
/* Class define */
|
57
58
|
/*********************************/
|
58
59
|
// turkey法
|
@@ -366,5 +367,55 @@ public class MultiComp {
|
|
366
367
|
}
|
367
368
|
}
|
368
369
|
}
|
370
|
+
public static class NonParametrixTest {
|
371
|
+
private static NonParametrixTest nonParamTest = new NonParametrixTest();
|
372
|
+
public static NonParametrixTest getInstance() {
|
373
|
+
return nonParamTest;
|
374
|
+
}
|
375
|
+
public boolean[][] bonferronoTest(double[][] xi, double a) {
|
376
|
+
HypothesisTest hypoth = new BonferroniTest();
|
377
|
+
|
378
|
+
double[][] statistic = hypoth.calcTestStatistic(xi);
|
379
|
+
return hypoth.executeTest(statistic, a * 0.5);
|
380
|
+
}
|
381
|
+
/*********************************/
|
382
|
+
/* Class define */
|
383
|
+
/*********************************/
|
384
|
+
// ボンフェロー法
|
385
|
+
private class BonferroniTest implements HypothesisTest {
|
386
|
+
private int n = 0;
|
387
|
+
private int k = 0;
|
388
|
+
public double[][] calcTestStatistic(double[][] xi) {
|
389
|
+
n = xi.length;
|
390
|
+
double[][] statistic = new double[n][n];
|
391
|
+
//
|
392
|
+
Combinations c = new Combinations(n, 2);
|
393
|
+
List<int[]> al = new ArrayList<>();
|
394
|
+
for(int[] iterate : c) {
|
395
|
+
al.add(iterate);
|
396
|
+
}
|
397
|
+
k = al.size();
|
398
|
+
//
|
399
|
+
MannWhitneyUTest utest = new MannWhitneyUTest();
|
400
|
+
for(int[] array : al) {
|
401
|
+
int i = array[0];
|
402
|
+
int j = array[1];
|
403
|
+
|
404
|
+
statistic[i][j] = utest.mannWhitneyUTest(xi[i], xi[j]);
|
405
|
+
}
|
406
|
+
return statistic;
|
407
|
+
}
|
408
|
+
public boolean[][] executeTest(double[][] statistic, double a) {
|
409
|
+
boolean[][] ret = new boolean[n][n];
|
410
|
+
|
411
|
+
for(int i = 0; i < n; i++) {
|
412
|
+
for(int j = i+1; j < n; j++) {
|
413
|
+
ret[i][j] = (statistic[i][j] < a * k) ? true : false;
|
414
|
+
}
|
415
|
+
}
|
416
|
+
return ret;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
}
|
369
420
|
}
|
370
421
|
|
data/lib/multicomp.rb
CHANGED
@@ -43,7 +43,7 @@ module MultiCompLib
|
|
43
43
|
ret = @paramTest.turkeyTest(xi.to_java(Java::double[]), a)
|
44
44
|
return ret.to_a
|
45
45
|
end
|
46
|
-
# ボンフェロー二の不等式による多重比較
|
46
|
+
# ボンフェロー二の不等式による多重比較(T検定)
|
47
47
|
#
|
48
48
|
# @overload bonferrono_test(xi, a)
|
49
49
|
# @param [array] xi データ(double[][])
|
@@ -74,5 +74,37 @@ module MultiCompLib
|
|
74
74
|
end
|
75
75
|
# ノンパラメトリック検定
|
76
76
|
class NonParametrixTestLib
|
77
|
+
def initialize
|
78
|
+
@nonParamTest = MultiComp::NonParametrixTest.getInstance()
|
79
|
+
end
|
80
|
+
# ボンフェロー二の不等式による多重比較(マン・ホイットニーU検定)
|
81
|
+
#
|
82
|
+
# @overload bonferrono_test(xi, a)
|
83
|
+
# @param [array] xi データ(double[][])
|
84
|
+
# @param [double] a 有意水準
|
85
|
+
# @return [Array] 検定結果(boolean[][] true:棄却域内 false:棄却域外)
|
86
|
+
# @example
|
87
|
+
# xi = [
|
88
|
+
# [12.2, 18.8, 18.2],
|
89
|
+
# [22.2, 20.5, 14.6],
|
90
|
+
# [20.8, 19.5, 26.3],
|
91
|
+
# [26.4, 32.5, 31.3],
|
92
|
+
# [24.5, 21.2, 22.4],
|
93
|
+
# ]
|
94
|
+
# nonParaTest = MultiCompLib::NonParametrixTestLib.new
|
95
|
+
# nonParaTest.bonferrono_test(xi, 0.05)
|
96
|
+
# =>
|
97
|
+
# [
|
98
|
+
# [false, false, true, true, true],
|
99
|
+
# [false, false, false, true, true],
|
100
|
+
# [false, false, false, true, false],
|
101
|
+
# [false, false, false, false, true],
|
102
|
+
# [false, false, false, false, false],
|
103
|
+
# ]
|
104
|
+
def bonferrono_test(xi, a)
|
105
|
+
ret = @nonParamTest.bonferronoTest(xi.to_java(Java::double[]), a)
|
106
|
+
return ret.to_a
|
107
|
+
end
|
108
|
+
|
77
109
|
end
|
78
110
|
end
|
data/lib/num4anova.rb
CHANGED
@@ -341,14 +341,24 @@ module Num4AnovaLib
|
|
341
341
|
# ancova = Num4AnovaLib::Num4AncovaLib.new
|
342
342
|
# ancova.interval_estim(xi, 0.05)
|
343
343
|
# =>
|
344
|
-
#
|
344
|
+
# {:min=>4.466605469341916, :max=>7.1909253948556096}
|
345
|
+
# {:min=>5.05699825110459, :max=>6.386335082228742}
|
346
|
+
# {:min=>2.510804295684195, :max=>4.250430272217034}
|
347
|
+
# {:min=>2.8089257316042135, :max=>2.9566298239513418}
|
348
|
+
# {:min=>-6.303283147572267, :max=>-0.6577045067487104}
|
345
349
|
def interval_estim(xi, a)
|
350
|
+
retRb = []
|
346
351
|
retJava = @ancova.intervalEstim(xi.to_java(Java::double[][]), a)
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
+
sz = retJava.size
|
353
|
+
sz.times do |i|
|
354
|
+
retRb.push(
|
355
|
+
{
|
356
|
+
"min": retJava[i].getMin(),
|
357
|
+
"max": retJava[i].getMax()
|
358
|
+
}
|
359
|
+
)
|
360
|
+
end
|
361
|
+
return retRb
|
352
362
|
end
|
353
363
|
end
|
354
364
|
end
|
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.14
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- siranovel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|