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 +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/num4anova/Ancova.java +145 -82
- data/lib/num4anova.rb +32 -2
- 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: 3dc8b0870b6c837111c8c59d391502dcea83fa1bb055834ccbe89823d24ba64a
|
4
|
+
data.tar.gz: d079fbc907bb2b0f72dc79affb51441efbbad8973842703194dac216be783e0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab2456e85fa85bb45fe021e5e6606353f7d957874ac6f5fe8f335ab78a4449c50f866ce5b8af14c5cfb5ece7b61bffc700c499d584e0d16df14c1d4e2370ab2
|
7
|
+
data.tar.gz: 0e43ed4956da47b8964f4f129ef27b46333c18f4c1cd84af0826f7f533ca7df185e2e9af83ce4cea202ad15d2115e4ed80c4335adfb7cf69654f39fbfd430af5
|
data/CHANGELOG.md
CHANGED
data/ext/num4anova/Ancova.java
CHANGED
@@ -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
|
-
|
26
|
-
|
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
|
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
|
-
|
51
|
-
|
52
|
-
double
|
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
|
55
|
-
double
|
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
|
-
|
64
|
-
|
65
|
-
double
|
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
|
-
|
62
|
+
double sumayx = calcSumayx(xi) - sumy*sumx / sumn;
|
63
|
+
double sumtyx = sumyx - sumy*sumx / sumn;
|
64
|
+
|
65
|
+
return sumtyx - sumayx;
|
68
66
|
}
|
69
|
-
|
70
|
-
|
67
|
+
// 平行性の検定
|
68
|
+
protected double calcbx(double[][][] xi) {
|
69
|
+
double sum = 0.0;
|
71
70
|
|
72
|
-
for(int i = 0; i < xi.length; i++) {
|
73
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
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]
|
121
|
+
sum += xi[i][j][1];
|
104
122
|
}
|
105
123
|
}
|
106
124
|
return sum;
|
107
125
|
}
|
108
|
-
|
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][
|
131
|
+
sum += xi[i][j][1] * xi[i][j][1];
|
114
132
|
}
|
115
133
|
}
|
116
134
|
return sum;
|
117
135
|
}
|
118
|
-
|
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 *
|
156
|
+
sum += sumxi * sumyi / xi[i].length;
|
138
157
|
}
|
139
158
|
return sum;
|
140
|
-
|
141
159
|
}
|
142
|
-
|
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
|
165
|
+
double sumxi = 0.0;
|
147
166
|
for (int j = 0; j < xi[i].length; j++) {
|
148
|
-
|
167
|
+
sumxi += xi[i][j][1];
|
149
168
|
}
|
150
|
-
sum +=
|
169
|
+
sum += sumxi * sumxi / xi[i].length;
|
151
170
|
}
|
152
171
|
return sum;
|
153
172
|
}
|
154
|
-
private double
|
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
|
-
|
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
|
-
|
170
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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
|
-
|
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
|
-
|
187
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
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]
|
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.
|
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-
|
11
|
+
date: 2024-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|