num4anova 0.0.5-java → 0.0.6-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a089d52ead2c9726d9ca61db475f128925afddca7cbcf6f65f0da75e41f0b1b
4
- data.tar.gz: 050e29e04bd0e8272da89d5aba231fe08294f50f090d261da7aa6822f5df5bc5
3
+ metadata.gz: 4dd60df363d899af7ca69bca4cb1da1689548f083abaacfd6441d5a589bf3501
4
+ data.tar.gz: 84469385e378cde1eddc3521582aefd2f5b2adce84e76d0c8a4c23bdd40d9374
5
5
  SHA512:
6
- metadata.gz: f0cc84d4cebb416b04ed0360ef4cf72799aaebcf70104b6e2d2dc2bc471400d3ac313b71f5885fd0854ae8b3ae22dd66c753066233b1ed2848aabf586cee2c05
7
- data.tar.gz: 88a74fb295e7ce0e0bdba405a14239a37fac4f3115bd29f358ce7b54fcc3b71a1533ff095e5aea7e2b141d867051eca703d179874f1ed349aef92575d8d0a186
6
+ metadata.gz: 7a036fe08363781f31b3583d7c7a454131680413e9c3aaeb0ebe135eec930912807e3f84be688d8bf70e1e56eafdefef0a3425f07eb18d6d042549dc2f7dd893
7
+ data.tar.gz: 7d7c136e1e457c08ac341fc542be1590888c233c161034eeff0f67d3d1466b4879ccd49c5f2a83e2f42f18f28a0279d66909d768d616afabf24b59be36a7e4e4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.6] - 2024-02-04
6
+
7
+ ### add
8
+ - add function of twoway2_anova.
9
+
5
10
  ## [0.0.5] - 2024-02-01
6
11
 
7
12
  ### add
@@ -12,6 +12,12 @@ public class TwoWayLayout {
12
12
  double[] statistic = twoway.calcTestStatistic(xij);
13
13
  return twoway.execute_test(statistic, a);
14
14
  }
15
+ public boolean[] twoway2Anova(double[][] xij, double a) {
16
+ TwoWay2AnovaTest twoway = new TwoWay2Anova();
17
+
18
+ double[] statistic = twoway.calcTestStatistic(xij);
19
+ return twoway.execute_test(statistic, a);
20
+ }
15
21
  /*********************************/
16
22
  /* interface define */
17
23
  /*********************************/
@@ -19,9 +25,14 @@ public class TwoWayLayout {
19
25
  double[] calcTestStatistic(double[][][] xij);
20
26
  boolean[] execute_test(double statistic[], double a);
21
27
  }
28
+ private interface TwoWay2AnovaTest {
29
+ double[] calcTestStatistic(double[][] xij);
30
+ boolean[] execute_test(double statistic[], double a);
31
+ }
22
32
  /*********************************/
23
33
  /* class define */
24
34
  /*********************************/
35
+ // 二元配置の分散分析(繰り返し数が等しい時)
25
36
  private class TwoWayAnova implements TwoWayAnovaTest {
26
37
  private int a = 0;
27
38
  private int b = 0;
@@ -32,6 +43,7 @@ public class TwoWayLayout {
32
43
  private int en = 0;
33
44
  public double[] calcTestStatistic(double[][][] xij) {
34
45
  double statistic[] = new double[3];
46
+
35
47
  a = xij.length;
36
48
  b = xij[0].length;
37
49
  n = xij[0][0].length;
@@ -45,7 +57,6 @@ public class TwoWayLayout {
45
57
  double[] meanBn = calcMeanBn(meanXij);
46
58
  double meanABn = calcMeanABn(meanAn);
47
59
 
48
- double allDrift = calcAllDrift(xij, meanABn); // 全変動
49
60
  double anDrift = calcAnDrift(meanAn, meanABn); // 水準Ai間変動
50
61
  double bnDrift = calcBnDrift(meanBn, meanABn); // 水準Bj間変動
51
62
  // 交互作用の変動
@@ -76,20 +87,17 @@ public class TwoWayLayout {
76
87
  }
77
88
  private double[] calcMeanAn(double[][] meanXij) {
78
89
  double[] an = new double[a];
79
- DescriptiveStatistics stat = new DescriptiveStatistics();
80
90
 
81
91
  for(int i = 0; i < a; i++) {
82
92
  double sumSa = 0.0;
83
93
  for(int j = 0; j < b; j++) {
84
- sumSa += meanXij[i][j];
94
+ an[i] += meanXij[i][j] / b;
85
95
  }
86
- an[i] = sumSa / b;
87
96
  }
88
97
  return an;
89
98
  }
90
99
  private double[] calcMeanBn(double[][] meanXij) {
91
100
  double[] bn = new double[b];
92
- double[] sumA = new double[b];
93
101
 
94
102
  for(int i = 0; i < a; i++) {
95
103
  for(int j = 0; j < b; j++) {
@@ -104,20 +112,6 @@ public class TwoWayLayout {
104
112
  Arrays.stream(meanAn).forEach(stat::addValue);
105
113
  return stat.getMean();
106
114
  }
107
- // 全変動
108
- private double calcAllDrift(double[][][] xij, double meanABn) {
109
- double sumDrift = 0.0;
110
-
111
- for(int i = 0; i < a; i++) {
112
- for(int j = 0; j < b; j++) {
113
- for(int k = 0; k < xij[i][j].length; k++) {
114
- double diffXijk = xij[i][j][k] - meanABn;
115
- sumDrift += diffXijk * diffXijk;
116
- }
117
- }
118
- }
119
- return sumDrift;
120
- }
121
115
  // 水準Ai間変動
122
116
  private double calcAnDrift(double[] meanAn, double meanABn) {
123
117
  double sumDrift = 0.0;
@@ -179,7 +173,113 @@ public class TwoWayLayout {
179
173
  private boolean evaluation(FDistribution fDist, double statistic, double a) {
180
174
  double r_val = fDist.inverseCumulativeProbability(1.0 - a);
181
175
 
182
- return (statistic < r_val) ? false : true;
176
+ return (statistic >= r_val) ? true : false;
177
+ }
178
+ }
179
+ // 二元配置の分散分析(繰り返しのない時)
180
+ private class TwoWay2Anova implements TwoWay2AnovaTest {
181
+ private int a = 0;
182
+ private int b = 0;
183
+ private int an = 0;
184
+ private int bn = 0;
185
+ private int en = 0;
186
+ public double[] calcTestStatistic(double[][] xij) {
187
+ double statistic[] = new double[2];
188
+
189
+ a = xij.length;
190
+ b = xij[0].length;
191
+ an = a- 1;
192
+ bn = b - 1;
193
+ en = (a- 1) * (b - 1);
194
+
195
+ double[] meanAn = calcMeanAn(xij);
196
+ double[] meanBn = calcMeanBn(xij);
197
+ double meanAB = calcMeanAB(meanAn);
198
+
199
+ double anDrift = calcAnDrift(meanAn, meanAB); // 水準Ai間変動
200
+ double bnDrift = calcBnDrift(meanBn, meanAB); // 水準Bj間変動
201
+ double benchDrift = calcBenchDrift(xij, meanAn, meanBn, meanAB); // 水準内変動
202
+ double va = anDrift / an;
203
+ double vb = bnDrift / bn;
204
+ double ve = benchDrift / en;
205
+
206
+ statistic[0] = va / ve;
207
+ statistic[1] = vb / ve;
208
+ return statistic;
209
+ }
210
+ private double[] calcMeanAn(double[][] xij) {
211
+ double[] an = new double[a];
212
+
213
+ for(int i = 0; i < a; i++) {
214
+ for(int j = 0; j < b; j++) {
215
+ an[i] += xij[i][j] / b;
216
+ }
217
+ }
218
+ return an;
219
+ }
220
+ private double[] calcMeanBn(double[][] xij) {
221
+ double[] bn = new double[b];
222
+
223
+ for(int i = 0; i < a; i++) {
224
+ for(int j = 0; j < b; j++) {
225
+ bn[j] += xij[i][j] / a;
226
+ }
227
+ }
228
+ return bn;
229
+ }
230
+ private double calcMeanAB(double[] meanAn) {
231
+ DescriptiveStatistics stat = new DescriptiveStatistics();
232
+
233
+ Arrays.stream(meanAn).forEach(stat::addValue);
234
+ return stat.getMean();
235
+ }
236
+ // 水準Ai間変動
237
+ private double calcAnDrift(double[] meanAn, double meanAB) {
238
+ double sumDrift = 0.0;
239
+
240
+ for(int i =0; i < meanAn.length; i++) {
241
+ double diffXi = meanAn[i] - meanAB;
242
+
243
+ sumDrift += diffXi * diffXi;
244
+ }
245
+ return b * sumDrift;
246
+ }
247
+ // 水準Bj間変動
248
+ private double calcBnDrift(double[] meanBn, double meanAB) {
249
+ double sumDrift = 0.0;
250
+
251
+ for(int j = 0; j < meanBn.length; j++) {
252
+ double diffXj = meanBn[j] - meanAB;
253
+
254
+ sumDrift += diffXj * diffXj;
255
+ }
256
+ return a * sumDrift;
257
+ }
258
+ // 水準内変動
259
+ private double calcBenchDrift(double[][] xij, double[] meanAn, double[] meanBn, double meanAB) {
260
+ double sumDrift = 0.0;
261
+
262
+ for(int i = 0; i < a; i++) {
263
+ for(int j = 0; j < b; j++) {
264
+ double diffXj = xij[i][j] - meanAn[i] - meanBn[j] + meanAB;
265
+
266
+ sumDrift += diffXj * diffXj;
267
+ }
268
+ }
269
+ return sumDrift;
270
+ }
271
+
272
+ public boolean[] execute_test(double statistic[], double a) {
273
+ boolean[] ret = new boolean[2];
274
+
275
+ ret[0] = evaluation(new FDistribution(an, en), statistic[0], a);
276
+ ret[1] = evaluation(new FDistribution(bn, en), statistic[1], a);
277
+ return ret;
278
+ }
279
+ private boolean evaluation(FDistribution fDist, double statistic, double a) {
280
+ double r_val = fDist.inverseCumulativeProbability(1.0 - a);
281
+
282
+ return (statistic >= r_val) ? true : false;
183
283
  }
184
284
  }
185
285
  }
data/lib/num4anova.rb CHANGED
@@ -158,6 +158,7 @@ module Num4AnovaLib
158
158
  @twoWay = TwoWayLayout.getInstance()
159
159
  end
160
160
  # 二元配置の分散分析
161
+ # (繰り返し数が等しい時)
161
162
  #
162
163
  # @overload twoway_anova(xij, a)
163
164
  # @param [array] xij データ(double[][][])
@@ -194,6 +195,28 @@ module Num4AnovaLib
194
195
  ret = @twoWay.twowayAnova(xij.to_java(Java::double[][]), a)
195
196
  return ret.to_a
196
197
  end
198
+ # 二元配置の分散分析
199
+ # (繰り返しのない時)
200
+ #
201
+ # @overload twoway2_anova(xij, a)
202
+ # @param [array] xij データ(double[][])
203
+ # @param [double] a 有意水準
204
+ # @return [Array] 検定結果(boolean[] true:棄却域内 false:棄却域外)
205
+ # @example
206
+ # xij = [
207
+ # [13.6, 15.6, 9.2],
208
+ # [22.3, 23.3, 13.3],
209
+ # [26.7, 28.8, 15.0],
210
+ # [28.0, 31.2, 15.8],
211
+ # ]
212
+ # twoWay = Num4AnovaLib::TwoWayLayoutLib.new
213
+ # twoWay.twoway2_anova(xij, 0.05)
214
+ # =>
215
+ # [true, true]
216
+ def twoway2_anova(xij, a)
217
+ ret = @twoWay.twoway2Anova(xij.to_java(Java::double[]), a)
218
+ return ret.to_a
219
+ end
197
220
  end
198
221
  end
199
222
 
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.5
4
+ version: 0.0.6
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-01 00:00:00.000000000 Z
11
+ date: 2024-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake