num4anova 0.0.9-java → 0.0.10-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: f5d31afc9315035a148a1b2a755ecc64422c64d82c548378c8f4ea3bb940d91d
4
- data.tar.gz: 249a18fb9ec372037d32b1bafc4ba37d35916e8d3fe25a96fc576f627e8ab89b
3
+ metadata.gz: 3dc8b0870b6c837111c8c59d391502dcea83fa1bb055834ccbe89823d24ba64a
4
+ data.tar.gz: d079fbc907bb2b0f72dc79affb51441efbbad8973842703194dac216be783e0b
5
5
  SHA512:
6
- metadata.gz: de66c54f9facc61769f2a40c4b936bcc8a6e93cfe8eb1d2d185504b9d9e59cfd6dc45654a2ec7f26a6a72c7debfef00396058a1c0db405b47e4deed7963382be
7
- data.tar.gz: 908b725baa8aa4b68102b66f65fb789cc496124283e210dfd0b7c05dac4c6e22701e3c2e5bcb16c6ec01631aa3b20a8e50908b994f3dfd78e8f5804dfb245391
6
+ metadata.gz: 2ab2456e85fa85bb45fe021e5e6606353f7d957874ac6f5fe8f335ab78a4449c50f866ce5b8af14c5cfb5ece7b61bffc700c499d584e0d16df14c1d4e2370ab2
7
+ data.tar.gz: 0e43ed4956da47b8964f4f129ef27b46333c18f4c1cd84af0826f7f533ca7df185e2e9af83ce4cea202ad15d2115e4ed80c4335adfb7cf69654f39fbfd430af5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.10] - 2024-03-05
6
+
7
+ ### add
8
+ - add fuction of significance_test.
9
+
5
10
  ## [0.0.9] - 2024-03-02
6
11
 
7
12
  ### add
@@ -11,6 +11,12 @@ public class Ancova {
11
11
  double statistic = hypoth.calcTestStatistic(xi);
12
12
  return hypoth.executeTest(statistic, a);
13
13
  }
14
+ public boolean significanceTest(double[][][] xi, double a) {
15
+ HypothesisTest hypoth = new SignificanceTest();
16
+
17
+ double statistic = hypoth.calcTestStatistic(xi);
18
+ return hypoth.executeTest(statistic, a);
19
+ }
14
20
  /*********************************/
15
21
  /* interface define */
16
22
  /*********************************/
@@ -21,101 +27,113 @@ public class Ancova {
21
27
  /*********************************/
22
28
  /* class define */
23
29
  /*********************************/
24
- // 回帰直線モデルの平行性の検定
25
- private class Parallettest implements HypothesisTest {
26
- private int n = 0;
27
- private int m = 0;
28
- public double calcTestStatistic(double[][][] xi) {
29
- int sumn = calcSumn(xi);
30
- double sumx = calcSumx(xi);
31
- double sumy = calcSumy(xi);
32
- n = xi.length - 1;
33
- m = sumn - 2 * xi.length;
30
+ private class RegressionLine {
31
+ protected int calcSumn(double[][][] xi) {
32
+ int sum = 0;
34
33
 
35
- // 全変動
34
+ for(int i = 0; i < xi.length; i++) {
35
+ sum += xi[i].length;
36
+ }
37
+ return sum;
38
+ }
39
+ protected double calcSex(double[][][] xi, int sumn) {
36
40
  double sumx2 = calcSumx2(xi);
37
- double sumy2 = calcSumy2(xi);
38
- double sumyx = calcSumyx(xi);
41
+ double sumx = calcSumx(xi);
39
42
 
40
43
  double sumtx = sumx2 - sumx*sumx / sumn;
41
- double sumty = sumy2 - sumy*sumy / sumn;
42
- double sumtyx = sumyx - sumy*sumx / sumn;
43
-
44
- // 水準間変動
45
44
  double sumax = calcSumax(xi) - sumx*sumx / sumn;
46
- double sumay = calcSumay(xi) - sumy*sumy / sumn;
47
- double sumayx = calcSumayx(xi) - sumy*sumx / sumn;
48
45
 
49
- // 水準内変動
50
- double sumex = sumtx - sumax;
51
- double sumey = sumty - sumay;
52
- double sumeyx = sumtyx - sumayx;
46
+ return sumtx - sumax;
47
+ }
48
+ protected double calcSey(double[][][] xi, int sumn) {
49
+ double sumy2 = calcSumy2(xi);
50
+ double sumy = calcSumy(xi);
53
51
 
54
- double sumbx = calcbx(xi);
55
- double sumnp = sumbx - sumeyx * sumeyx / sumex;
56
- double sume2 = sumey - sumbx;
52
+ double sumay = calcSumay(xi) - sumy*sumy / sumn;
53
+ double sumty = sumy2 - sumy*sumy / sumn;
57
54
 
58
- //
59
- double vnp = sumnp / n;
60
- double ve2 = sume2 / m;
61
- return vnp / ve2;
55
+ return sumty - sumay;
62
56
  }
63
- public boolean executeTest(double statistic, double a) {
64
- FDistribution fDist = new FDistribution(n, m);
65
- double f = fDist.inverseCumulativeProbability(1.0 - a);
57
+ protected double calcSeyx(double[][][] xi, int sumn) {
58
+ double sumx = calcSumx(xi);
59
+ double sumy = calcSumy(xi);
60
+ double sumyx = calcSumyx(xi);
66
61
 
67
- return (statistic >= f) ? true : false;
62
+ double sumayx = calcSumayx(xi) - sumy*sumx / sumn;
63
+ double sumtyx = sumyx - sumy*sumx / sumn;
64
+
65
+ return sumtyx - sumayx;
68
66
  }
69
- private int calcSumn(double[][][] xi) {
70
- int sum = 0;
67
+ // 平行性の検定
68
+ protected double calcbx(double[][][] xi) {
69
+ double sum = 0.0;
71
70
 
72
- for(int i = 0; i < xi.length; i++) {
73
- sum += xi[i].length;
71
+ for (int i = 0; i < xi.length; i++) {
72
+ int n = xi[i].length;
73
+ double sumx = 0.0;
74
+ double sumy = 0.0;
75
+ double sumyx = 0.0;
76
+ double sumx2 = 0.0;
77
+ for (int j = 0; j < n; j++) {
78
+ sumx += xi[i][j][1];
79
+ sumy += xi[i][j][0];
80
+ sumyx += xi[i][j][1] * xi[i][j][0];
81
+
82
+ sumx2 += xi[i][j][1] * xi[i][j][1];
83
+
84
+ }
85
+ double wki = n * sumyx - sumy * sumx;
86
+ double wk = wki * wki / (n * (n * sumx2 - sumx * sumx));
87
+
88
+ sum += wk;
74
89
  }
75
90
  return sum;
76
91
  }
77
- // 全変動
78
- private double calcSumx(double[][][] xi) {
92
+
93
+
94
+ private double calcSumay(double[][][] xi) {
79
95
  double sum = 0.0;
80
96
 
81
97
  for (int i = 0; i < xi.length; i++) {
98
+ double sumyi = 0.0;
82
99
  for (int j = 0; j < xi[i].length; j++) {
83
- sum += xi[i][j][1];
100
+ sumyi += xi[i][j][0];
84
101
  }
102
+ sum += sumyi * sumyi / xi[i].length;
85
103
  }
86
104
  return sum;
87
105
  }
88
- private double calcSumy(double[][][] xi) {
106
+ private double calcSumy2(double[][][] xi) {
89
107
  double sum = 0.0;
90
108
 
91
109
  for (int i = 0; i < xi.length; i++) {
92
110
  for (int j = 0; j < xi[i].length; j++) {
93
- sum += xi[i][j][0];
111
+ sum += xi[i][j][0] * xi[i][j][0];
94
112
  }
95
113
  }
96
114
  return sum;
97
115
  }
98
- private double calcSumx2(double[][][] xi) {
116
+ private double calcSumx(double[][][] xi) {
99
117
  double sum = 0.0;
100
118
 
101
119
  for (int i = 0; i < xi.length; i++) {
102
120
  for (int j = 0; j < xi[i].length; j++) {
103
- sum += xi[i][j][1] * xi[i][j][1];
121
+ sum += xi[i][j][1];
104
122
  }
105
123
  }
106
124
  return sum;
107
125
  }
108
- private double calcSumy2(double[][][] xi) {
126
+ protected double calcSumx2(double[][][] xi) {
109
127
  double sum = 0.0;
110
128
 
111
129
  for (int i = 0; i < xi.length; i++) {
112
130
  for (int j = 0; j < xi[i].length; j++) {
113
- sum += xi[i][j][0] * xi[i][j][0];
131
+ sum += xi[i][j][1] * xi[i][j][1];
114
132
  }
115
133
  }
116
134
  return sum;
117
135
  }
118
- private double calcSumyx(double[][][] xi) {
136
+ protected double calcSumyx(double[][][] xi) {
119
137
  double sum = 0.0;
120
138
 
121
139
  for (int i = 0; i < xi.length; i++) {
@@ -125,70 +143,115 @@ public class Ancova {
125
143
  }
126
144
  return sum;
127
145
  }
128
- // 水準間変動
129
- private double calcSumax(double[][][] xi) {
146
+ private double calcSumayx(double[][][] xi) {
130
147
  double sum = 0.0;
131
148
 
132
149
  for (int i = 0; i < xi.length; i++) {
133
150
  double sumxi = 0.0;
151
+ double sumyi = 0.0;
134
152
  for (int j = 0; j < xi[i].length; j++) {
135
153
  sumxi += xi[i][j][1];
154
+ sumyi += xi[i][j][0];
136
155
  }
137
- sum += sumxi * sumxi / xi[i].length;
156
+ sum += sumxi * sumyi / xi[i].length;
138
157
  }
139
158
  return sum;
140
-
141
159
  }
142
- private double calcSumay(double[][][] xi) {
160
+ // 水準間変動
161
+ private double calcSumax(double[][][] xi) {
143
162
  double sum = 0.0;
144
163
 
145
164
  for (int i = 0; i < xi.length; i++) {
146
- double sumyi = 0.0;
165
+ double sumxi = 0.0;
147
166
  for (int j = 0; j < xi[i].length; j++) {
148
- sumyi += xi[i][j][0];
167
+ sumxi += xi[i][j][1];
149
168
  }
150
- sum += sumyi * sumyi / xi[i].length;
169
+ sum += sumxi * sumxi / xi[i].length;
151
170
  }
152
171
  return sum;
153
172
  }
154
- private double calcSumayx(double[][][] xi) {
173
+ private double calcSumy(double[][][] xi) {
155
174
  double sum = 0.0;
156
175
 
157
176
  for (int i = 0; i < xi.length; i++) {
158
- double sumxi = 0.0;
159
- double sumyi = 0.0;
160
177
  for (int j = 0; j < xi[i].length; j++) {
161
- sumxi += xi[i][j][1];
162
- sumyi += xi[i][j][0];
178
+ sum += xi[i][j][0];
163
179
  }
164
- sum += sumxi * sumyi / xi[i].length;
165
180
  }
166
181
  return sum;
167
182
  }
168
- // 平行性の検定
169
- private double calcbx(double[][][] xi) {
170
- double sum = 0.0;
183
+ }
184
+ // 回帰直線モデルの平行性の検定
185
+ private class Parallettest extends RegressionLine implements HypothesisTest {
186
+ private int n = 0;
187
+ private int m = 0;
188
+ public double calcTestStatistic(double[][][] xi) {
189
+ int sumn = calcSumn(xi);
190
+ n = xi.length - 1;
191
+ m = sumn - 2 * xi.length;
192
+
193
+ double vnp = calcVnp(xi, sumn);
194
+ double ve2 = calcVe2(xi, sumn);
171
195
 
172
- for (int i = 0; i < xi.length; i++) {
173
- int n = xi[i].length;
174
- double sumx = 0.0;
175
- double sumy = 0.0;
176
- double sumyx = 0.0;
177
- double sumx2 = 0.0;
178
- for (int j = 0; j < n; j++) {
179
- sumx += xi[i][j][1];
180
- sumy += xi[i][j][0];
181
- sumyx += xi[i][j][1] * xi[i][j][0];
196
+ return vnp / ve2;
197
+ }
198
+ private double calcVnp(double[][][] xi, int sumn){
199
+ return calcSnp(xi, sumn) / n;
200
+ }
201
+ private double calcSnp(double[][][] xi, int sumn) {
202
+ double sumbx = calcbx(xi);
203
+ double sumeyx = calcSeyx(xi, sumn);
204
+ double sumex = calcSex(xi, sumn);
182
205
 
183
- sumx2 += xi[i][j][1] * xi[i][j][1];
206
+ return sumbx - sumeyx * sumeyx / sumex;
207
+ }
208
+ private double calcVe2(double[][][] xi, int sumn) {
209
+ return calcSe2(xi, sumn) / m;
210
+ }
211
+ private double calcSe2(double[][][] xi, int sumn) {
212
+ double sumey = calcSey(xi, sumn);
213
+ double sumbx = calcbx(xi);
184
214
 
185
- }
186
- double wki = n * sumyx - sumy * sumx;
187
- double wk = wki * wki / (n * (n * sumx2 - sumx * sumx));
215
+ return sumey - sumbx;
216
+ }
217
+ public boolean executeTest(double statistic, double a) {
218
+ FDistribution fDist = new FDistribution(n, m);
219
+ double f = fDist.inverseCumulativeProbability(1.0 - a);
188
220
 
189
- sum += wk;
190
- }
191
- return sum;
221
+ return (statistic >= f) ? true : false;
222
+ }
223
+ }
224
+ // 回帰直線モデルの平行性の検定
225
+ private class SignificanceTest extends RegressionLine implements HypothesisTest {
226
+ private int n = 0;
227
+ private int m = 0;
228
+ public double calcTestStatistic(double[][][] xi) {
229
+ int sumn = calcSumn(xi);
230
+ n = 1;
231
+ m = sumn - xi.length - 1;
232
+
233
+ double vr = calcVr(xi, sumn);
234
+ double ve = calcVe(xi, sumn);
235
+ return vr / ve;
236
+ }
237
+ public boolean executeTest(double statistic, double a) {
238
+ FDistribution fDist = new FDistribution(n, m);
239
+ double f = fDist.inverseCumulativeProbability(1.0 - a);
240
+
241
+ return (statistic >= f) ? true : false;
242
+ }
243
+ private double calcVr(double[][][] xi, int sumn) {
244
+ double sumeyx = calcSeyx(xi, sumn);
245
+ double sumex = calcSex(xi, sumn);
246
+
247
+ return (sumeyx * sumeyx) / sumex;
248
+ }
249
+ private double calcVe(double[][][] xi, int sumn) {
250
+ double sumey = calcSey(xi, sumn);
251
+ double sumex = calcSex(xi, sumn);
252
+ double sumeyx = calcSeyx(xi, sumn);
253
+
254
+ return (sumey * sumex - sumeyx * sumeyx) / (m * sumex);
192
255
  }
193
256
  }
194
257
  }
data/lib/num4anova.rb CHANGED
@@ -228,8 +228,8 @@ module Num4AnovaLib
228
228
  #
229
229
  # @overload parallel_test(xi, a)
230
230
  # @param [array] xi データ(double[][][])
231
- # @param [double] a 有意水準
232
- # @return [boolean] 検定結果(boolean true:棄却域内 false:棄却域外)
231
+ # @param [double] a 有意水準
232
+ # @return [boolean] 検定結果(boolean true:棄却域内 false:棄却域外)
233
233
  # @example
234
234
  # xi = [
235
235
  # [
@@ -254,6 +254,36 @@ module Num4AnovaLib
254
254
  def parallel_test(xi, a)
255
255
  @ancova.parallelTest(xi.to_java(Java::double[][]), a)
256
256
  end
257
+ # 回帰直線の有意性検定
258
+ #
259
+ # @overload significance_testt(xi, a)
260
+ # @param [array] xi データ(double[][][])
261
+ # @param [double] a 有意水準
262
+ # @return [boolean] 検定結果(boolean true:棄却域内 false:棄却域外)
263
+ # @example
264
+ # xi = [
265
+ # [
266
+ # [3,35], [5,38], [3,39],
267
+ # ],
268
+ # [
269
+ # [3,36], [3,39], [8,54],
270
+ # ],
271
+ # [
272
+ # [2,40], [2,45], [2,39],
273
+ # ],
274
+ # [
275
+ # [3,47], [4,52], [2,48],
276
+ # ],
277
+ # [
278
+ # [1,64], [2,80], [0,70],
279
+ # ],
280
+ # ]
281
+ # ancova = Num4AnovaLib::Num4AncovaLib.new
282
+ # ancova.significance_test(xi, 0.05)
283
+ # => true
284
+ def significance_test(xi, a)
285
+ @ancova.significanceTest(xi.to_java(Java::double[][]), a)
286
+ end
257
287
  end
258
288
  end
259
289
 
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.9
4
+ version: 0.0.10
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-02 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake