num4anova 0.0.15-java → 0.0.16-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/TwoWayLayout.java +78 -4
- data/lib/num4anova.rb +25 -5
- 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: fb1dd347cd1156e1cc9e06ee7b4daff32442d6fc721e35553cbb406ae5d94cf1
|
4
|
+
data.tar.gz: 17d4c4084a40fe8e721829169e2551455d258f64dd4ef6c537b499ef9a5dab15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 768b64803a235265e1dae41341428a0bda9fb12245e7f2fae54a3f75f8aeee607a4cd3709b578b1c7aeb6869fcc7f227b287d2142b99411ed8955248eeafedd4
|
7
|
+
data.tar.gz: da4c649d32a38c9f9a83adadc54d20605bfebe42f822fdd353df7ba8e00df8e3be8fbd8c4775474da5299957a477ec98c4912ec1ac5b8fb0d305c0f11ad91ff0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
2
2
|
import org.apache.commons.math3.distribution.FDistribution;
|
3
|
+
import org.apache.commons.math3.distribution.ChiSquaredDistribution;
|
3
4
|
import java.util.Arrays;
|
5
|
+
|
6
|
+
import org.apache.commons.math3.stat.ranking.NaNStrategy;
|
7
|
+
import org.apache.commons.math3.stat.ranking.NaturalRanking;
|
8
|
+
import org.apache.commons.math3.stat.ranking.TiesStrategy;
|
4
9
|
public class TwoWayLayout {
|
5
10
|
private static TwoWayLayout twoWay = new TwoWayLayout();
|
6
11
|
public static TwoWayLayout getInstance() {
|
@@ -18,16 +23,26 @@ public class TwoWayLayout {
|
|
18
23
|
double[] statistic = twoway.calcTestStatistic(xij);
|
19
24
|
return twoway.execute_test(statistic, a);
|
20
25
|
}
|
26
|
+
public boolean friedmanTest(double[][] xij, double a) {
|
27
|
+
OneWayAnovaTest twoway = new FriedmanTest();
|
28
|
+
|
29
|
+
double statistic = twoway.calcTestStatistic(xij);
|
30
|
+
return twoway.execute_test(statistic, a);
|
31
|
+
}
|
21
32
|
/*********************************/
|
22
33
|
/* interface define */
|
23
34
|
/*********************************/
|
24
35
|
private interface TwoWayAnovaTest {
|
25
36
|
double[] calcTestStatistic(double[][][] xij);
|
26
|
-
boolean[] execute_test(double statistic
|
37
|
+
boolean[] execute_test(double[] statistic, double a);
|
27
38
|
}
|
28
39
|
private interface TwoWay2AnovaTest {
|
29
40
|
double[] calcTestStatistic(double[][] xij);
|
30
|
-
boolean[] execute_test(double statistic
|
41
|
+
boolean[] execute_test(double[] statistic, double a);
|
42
|
+
}
|
43
|
+
private interface OneWayAnovaTest {
|
44
|
+
double calcTestStatistic(double[][] xi);
|
45
|
+
boolean execute_test(double statistic, double a);
|
31
46
|
}
|
32
47
|
/*********************************/
|
33
48
|
/* class define */
|
@@ -162,7 +177,7 @@ public class TwoWayLayout {
|
|
162
177
|
}
|
163
178
|
return sumDrift;
|
164
179
|
}
|
165
|
-
public boolean[] execute_test(double statistic
|
180
|
+
public boolean[] execute_test(double[] statistic, double a) {
|
166
181
|
boolean[] ret = new boolean[3];
|
167
182
|
|
168
183
|
ret[0] = evaluation(new FDistribution(an, en), statistic[0], a);
|
@@ -269,7 +284,7 @@ public class TwoWayLayout {
|
|
269
284
|
return sumDrift;
|
270
285
|
}
|
271
286
|
|
272
|
-
public boolean[] execute_test(double statistic
|
287
|
+
public boolean[] execute_test(double[] statistic, double a) {
|
273
288
|
boolean[] ret = new boolean[2];
|
274
289
|
|
275
290
|
ret[0] = evaluation(new FDistribution(an, en), statistic[0], a);
|
@@ -282,5 +297,64 @@ public class TwoWayLayout {
|
|
282
297
|
return (statistic >= r_val) ? true : false;
|
283
298
|
}
|
284
299
|
}
|
300
|
+
// フリードマンの検定
|
301
|
+
private class FriedmanTest implements OneWayAnovaTest{
|
302
|
+
private NaturalRanking naturalRanking;
|
303
|
+
private int n = 0;
|
304
|
+
private int k = 0;
|
305
|
+
public FriedmanTest() {
|
306
|
+
naturalRanking = new NaturalRanking(NaNStrategy.FIXED,
|
307
|
+
TiesStrategy.AVERAGE);
|
308
|
+
}
|
309
|
+
public double calcTestStatistic(double[][] xij) {
|
310
|
+
n = xij[0].length;
|
311
|
+
k = xij.length;
|
312
|
+
double[][] z = concatSample(xij);
|
313
|
+
double[][] ranks = calcRankij(z);
|
314
|
+
double[] sumRankXi = calcSumRankXi(ranks);
|
315
|
+
double kw = 0.0;
|
316
|
+
|
317
|
+
for(int i = 0; i < sumRankXi.length; i++) {
|
318
|
+
kw += sumRankXi[i] * sumRankXi[i];
|
319
|
+
}
|
320
|
+
return 12.0 / (n * k * (k + 1.0)) * kw - 3.0 * n * (k + 1.0);
|
321
|
+
}
|
322
|
+
public boolean execute_test(double statistic, double a) {
|
323
|
+
ChiSquaredDistribution chi2Dist = new ChiSquaredDistribution(k - 1);
|
324
|
+
|
325
|
+
double r_val = chi2Dist.inverseCumulativeProbability(1.0 - a);
|
326
|
+
|
327
|
+
return (r_val < statistic) ? true : false;
|
328
|
+
}
|
329
|
+
private double[][] concatSample(double[][] xi) {
|
330
|
+
double[][] z = new double[n][k];
|
331
|
+
|
332
|
+
for(int i = 0; i < k; i++) {
|
333
|
+
for(int j = 0; j < n; j++) {
|
334
|
+
z[j][i] = xi[i][j];
|
335
|
+
}
|
336
|
+
}
|
337
|
+
return z;
|
338
|
+
}
|
339
|
+
private double[][] calcRankij(double[][] z) {
|
340
|
+
double[][] ranks = new double[n][k];
|
341
|
+
|
342
|
+
for(int i = 0; i < n; i++) {
|
343
|
+
ranks[i] = naturalRanking.rank(z[i]);
|
344
|
+
}
|
345
|
+
return ranks;
|
346
|
+
}
|
347
|
+
private double[] calcSumRankXi(double[][] ranks) {
|
348
|
+
double[] sumRi = new double[k];
|
349
|
+
|
350
|
+
for(int i = 0; i < k; i++) {
|
351
|
+
sumRi[i] = 0.0;
|
352
|
+
for(int j = 0; j < n; j++) {
|
353
|
+
sumRi[i] += ranks[j][i];
|
354
|
+
}
|
355
|
+
}
|
356
|
+
return sumRi;
|
357
|
+
}
|
358
|
+
}
|
285
359
|
}
|
286
360
|
|
data/lib/num4anova.rb
CHANGED
@@ -157,12 +157,11 @@ module Num4AnovaLib
|
|
157
157
|
# @param [array] xi データ(double[][])
|
158
158
|
# @param [double] a 有意水準
|
159
159
|
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
160
|
+
# @example
|
160
161
|
# xi = [
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
# [26.4, 32.5, 31.3],
|
165
|
-
# [24.5, 21.2, 22.4],
|
162
|
+
# [12.2, 18.8, 18.2],
|
163
|
+
# [22.2, 20.5, 14.6, 20.8, 19.5, 26.3],
|
164
|
+
# [26.4, 32.5, 31.3, 24.5, 21.2, 22.4],
|
166
165
|
# ]
|
167
166
|
# oneWay = Num4AnovaLib::OneWayLayoutLib.new
|
168
167
|
# oneWay.kruskalwallis_test(xi, 0.05)
|
@@ -236,6 +235,27 @@ module Num4AnovaLib
|
|
236
235
|
def twoway2_anova(xij, a)
|
237
236
|
ret = @twoWay.twoway2Anova(xij.to_java(Java::double[]), a)
|
238
237
|
return ret.to_a
|
238
|
+
end
|
239
|
+
# フリードマン検定
|
240
|
+
#
|
241
|
+
# @overload friedman_test(xij, a)
|
242
|
+
# @param [array] xij データ(double[][])
|
243
|
+
# @param [double] a 有意水準
|
244
|
+
# @return [boolean] 検定結果(boolean true:棄却域内 false:棄却域外)
|
245
|
+
# @example
|
246
|
+
# xij = [
|
247
|
+
# [13.6, 15.6, 9.2],
|
248
|
+
# [22.3, 23.3, 13.3],
|
249
|
+
# [26.7, 28.8, 15.0],
|
250
|
+
# [28.0, 31.2, 15.8],
|
251
|
+
# ]
|
252
|
+
# twoWay = Num4AnovaLib::TwoWayLayoutLib.new
|
253
|
+
# twoWay.friedman_test(xij, 0.05)
|
254
|
+
# =>
|
255
|
+
# true
|
256
|
+
def friedman_test(xij, a)
|
257
|
+
ret = @twoWay.friedmanTest(xij.to_java(Java::double[]), a)
|
258
|
+
return ret
|
239
259
|
end
|
240
260
|
end
|
241
261
|
# 共分散分析
|
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.16
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- siranovel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|