num4hypothtst 0.0.5-java → 0.0.7-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6ff3dd6e82c9be96c99627583dc57403f357a9fd7cfd47d20b4a9b91aa169ff
4
- data.tar.gz: 52b8a0961a549a213d35e431b73b50935642a4f2ad5aa69cf05ca9637577b1bb
3
+ metadata.gz: ddedb6b175ca41c15b5ebe6328faaa1cb05bfac2ca7098147960cdb4ab952dfd
4
+ data.tar.gz: a42501c4c92de4bbcffb5c7da8be7098101d890d947fbc98ec4e486be6122f7e
5
5
  SHA512:
6
- metadata.gz: 6da36a8c168a2a0055483738640ccecb5babb6d3268c109240e330a7cae3da486582dcef1271336402e2cba567911a2e0e59ef6c25c8963ef4428283be387821
7
- data.tar.gz: 43af75b2187bdb1e4fce7202b5414cfd1534ab4246f30713cfa8ddee56457bbc4d03ebb5a5ca0ca4d271a32acba2512877fe8b70974a6db7eefa2190ebf79d2e
6
+ metadata.gz: 1cea2d82655c054806b9a021503a4966e9e1bbf12937e09be304e4ecc95f84004d3680920373a3891bbb9b44941623993c921bcf127bca7f821f0247cbec7356
7
+ data.tar.gz: a9b38cb24b307f86284075791454ec5b5452abeaa7d010b6711adda1d08c6f52fe5800f16c40e5025ab8669859df58364801e4d26010d658d63ed63b7dad54d6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.7] - 2024-01-08
6
+
7
+ ### change
8
+ - function of gntest is bug fix.
9
+
10
+ ## [0.0.6] - 2023-12-27
11
+
12
+ ### delete
13
+ - del function of wilcoxon.
14
+
15
+ ### add
16
+ - add function of decorrelation.
17
+ - add function of populationCorre.
18
+
5
19
  ## [0.0.5] - 2023-12-19
6
20
 
7
21
  ### add
@@ -0,0 +1,16 @@
1
+ package hypothtst;
2
+
3
+ import org.apache.commons.math3.distribution.TDistribution;
4
+ public class DecorrTest implements HypothTest {
5
+ private static HypothTest hypothTest = new DecorrTest();
6
+ public static HypothTest getInstance() {
7
+ return hypothTest;
8
+ }
9
+ public boolean twoSideTest(double r, int n, double a) {
10
+ double statistic = Math.abs(r) * Math.sqrt(n - 2.0) / Math.sqrt(1.0 - r * r);
11
+ TDistribution tDist = new TDistribution(n - 2);
12
+ double p = 1.0 - tDist.cumulativeProbability(statistic);
13
+
14
+ return (p < a) ? true : false;
15
+ }
16
+ }
@@ -2,10 +2,10 @@ package hypothtst;
2
2
 
3
3
  import org.apache.commons.math3.distribution.TDistribution;
4
4
  // グラブス・スミルノフの外れ値の検定
5
- public class GrubbsTest {
6
- private static GrubbsTest grubbs = new GrubbsTest();
7
- public static GrubbsTest getInstance() {
8
- return grubbs;
5
+ public class GrubbsTest implements HypothTest2 {
6
+ private static HypothTest2 hypothTest2 = new GrubbsTest();
7
+ public static HypothTest2 getInstance() {
8
+ return hypothTest2;
9
9
  }
10
10
  public boolean twoSideTest(double statistic, int n, double a) {
11
11
  double r_val = calcGnValue(n, a / 2.0);
@@ -15,8 +15,9 @@ public class GrubbsTest {
15
15
  double r_val = calcGnValue(n, a);
16
16
  return evaluation(statistic, r_val);
17
17
  }
18
+
18
19
  private double calcGnValue(int n, double a) {
19
- TDistribution tDist = new TDistribution(n);
20
+ TDistribution tDist = new TDistribution(n - 2);
20
21
  double t = tDist.inverseCumulativeProbability(a / n);
21
22
  double gn = (n - 1) * t / Math.sqrt(n * (n - 2 + t * t));
22
23
 
@@ -2,10 +2,6 @@ package hypothtst;
2
2
 
3
3
  // 仮設検定
4
4
  interface HypothTest {
5
- boolean tDistTest(double statistic, double df, double a);
6
- boolean chi2DistTest(double statistic, double df, double a);
7
- boolean normDistTest(double statistic, double a);
8
- boolean fDistTest(double statistic, double nf, double df, double a);
9
- boolean wilcoxon(double statistic, int n, double a);
5
+ boolean twoSideTest(double statistic, int n, double a);
10
6
  }
11
7
 
@@ -0,0 +1,8 @@
1
+ package hypothtst;
2
+
3
+ // 仮設検定
4
+ interface HypothTest2 {
5
+ boolean twoSideTest(double statistic, int n, double a);
6
+ boolean oneSideTest(double statistic, int n, double a);
7
+ }
8
+
@@ -0,0 +1,12 @@
1
+ package hypothtst;
2
+
3
+ // 仮設検定
4
+ interface HypothTest3 {
5
+ boolean tDistTest(double statistic, double df, double a);
6
+ boolean chi2DistTest(double statistic, double df, double a);
7
+ boolean normDistTest(double statistic, double a);
8
+ boolean fDistTest(double statistic, double nf, double df, double a);
9
+
10
+ boolean populationCorre(double r, int n, double rth0, double a);
11
+ }
12
+
@@ -6,10 +6,10 @@ import org.apache.commons.math3.distribution.NormalDistribution;
6
6
  import org.apache.commons.math3.distribution.FDistribution;
7
7
 
8
8
  // 片側検定(左側)
9
- public class LeftSideTest implements HypothTest {
10
- private static HypothTest hupothTest = new LeftSideTest();
11
- public static HypothTest getInstance() {
12
- return hupothTest;
9
+ public class LeftSideTest implements HypothTest3 {
10
+ private static HypothTest3 hypothTest3 = new LeftSideTest();
11
+ public static HypothTest3 getInstance() {
12
+ return hypothTest3;
13
13
  }
14
14
  public boolean tDistTest(double statistic, double df, double a) {
15
15
  TDistribution tDist = new TDistribution(df);
@@ -35,15 +35,16 @@ public class LeftSideTest implements HypothTest {
35
35
 
36
36
  return evaluation(statistic, l_val);
37
37
  }
38
- public boolean wilcoxon(double statistic, int n, double a) {
39
- boolean ret = true;
40
- double e_t = n * (n + 1.0) / 4.0;
41
- double var_t = n * (n + 1.0) * (2.0 * n + 1.0) / 24.0;
42
- double z = (statistic - e_t) / Math.sqrt(var_t);
43
-
44
- return normDistTest(z, a);
38
+ public boolean populationCorre(double r, int n, double rth0, double a) {
39
+ double statistic = Math.sqrt(n-3.0) *
40
+ (
41
+ 0.5 * Math.log((1.0 + r) / (1.0 - r))
42
+ - 0.5 * Math.log((1.0 + rth0) / (1.0 - rth0))
43
+ );
44
+
45
+ return normDistTest(statistic, a);
45
46
  }
46
-
47
+
47
48
  private boolean evaluation(double statistic, double l_val) {
48
49
  boolean ret = true;
49
50
 
@@ -5,10 +5,10 @@ import org.apache.commons.math3.distribution.ChiSquaredDistribution;
5
5
  import org.apache.commons.math3.distribution.NormalDistribution;
6
6
  import org.apache.commons.math3.distribution.FDistribution;
7
7
  // 片側検定(右側)
8
- public class RightSideTest implements HypothTest {
9
- private static HypothTest hupothTest = new RightSideTest();
10
- public static HypothTest getInstance() {
11
- return hupothTest;
8
+ public class RightSideTest implements HypothTest3 {
9
+ private static HypothTest3 hypothTest3 = new RightSideTest();
10
+ public static HypothTest3 getInstance() {
11
+ return hypothTest3;
12
12
  }
13
13
  public boolean tDistTest(double statistic, double df, double a) {
14
14
  TDistribution tDist = new TDistribution(df);
@@ -34,14 +34,16 @@ public class RightSideTest implements HypothTest {
34
34
 
35
35
  return evaluation(statistic, r_val);
36
36
  }
37
- public boolean wilcoxon(double statistic, int n, double a) {
38
- boolean ret = true;
39
- double e_t = n * (n + 1.0) / 4.0;
40
- double var_t = n * (n + 1.0) * (2.0 * n + 1.0) / 24.0;
41
- double z = (statistic - e_t) / Math.sqrt(var_t);
42
-
43
- return normDistTest(z, a);
37
+ public boolean populationCorre(double r, int n, double rth0, double a) {
38
+ double statistic = Math.sqrt(n-3.0) *
39
+ (
40
+ 0.5 * Math.log((1.0 + r) / (1.0 - r))
41
+ - 0.5 * Math.log((1.0 + rth0) / (1.0 - rth0))
42
+ );
43
+
44
+ return normDistTest(statistic, a);
44
45
  }
46
+
45
47
  private boolean evaluation(double statistic, double r_val) {
46
48
  boolean ret = true;
47
49
 
@@ -6,10 +6,10 @@ import org.apache.commons.math3.distribution.NormalDistribution;
6
6
  import org.apache.commons.math3.distribution.FDistribution;
7
7
 
8
8
  // 両側検定
9
- public class TwoSideTest implements HypothTest {
10
- private static HypothTest hupothTest = new TwoSideTest();
11
- public static HypothTest getInstance() {
12
- return hupothTest;
9
+ public class TwoSideTest implements HypothTest3 {
10
+ private static HypothTest3 hypothTest3 = new TwoSideTest();
11
+ public static HypothTest3 getInstance() {
12
+ return hypothTest3;
13
13
  }
14
14
  public boolean tDistTest(double statistic, double df, double a) {
15
15
  TDistribution tDist = new TDistribution(df);
@@ -39,13 +39,14 @@ public class TwoSideTest implements HypothTest {
39
39
 
40
40
  return evaluation(statistic, l_val, r_val);
41
41
  }
42
- public boolean wilcoxon(double statistic, int n, double a) {
43
- boolean ret = true;
44
- double e_t = n * (n + 1.0) / 4.0;
45
- double var_t = n * (n + 1.0) * (2.0 * n + 1.0) / 24.0;
46
- double z = (statistic - e_t) / Math.sqrt(var_t);
47
-
48
- return normDistTest(z, a);
42
+ public boolean populationCorre(double r, int n, double rth0, double a) {
43
+ double statistic = Math.sqrt(n-3.0) *
44
+ (
45
+ 0.5 * Math.log((1.0 + r) / (1.0 - r))
46
+ - 0.5 * Math.log((1.0 + rth0) / (1.0 - rth0))
47
+ );
48
+
49
+ return normDistTest(statistic, a);
49
50
  }
50
51
 
51
52
  private boolean evaluation(double statistic, double l_val, double r_val) {
data/lib/num4hypothtst.rb CHANGED
@@ -6,6 +6,7 @@ java_import 'hypothtst.TwoSideTest'
6
6
  java_import 'hypothtst.RightSideTest'
7
7
  java_import 'hypothtst.LeftSideTest'
8
8
  java_import 'hypothtst.GrubbsTest'
9
+ java_import 'hypothtst.DecorrTest'
9
10
 
10
11
  # 統計的仮設検定のためのライブラリ
11
12
  # (Apache commoms math3使用)
@@ -13,7 +14,7 @@ module Num4HypothTestLib
13
14
  # 両側検定
14
15
  class TwoSideTestLib
15
16
  def initialize
16
- @hypothTest = TwoSideTest.getInstance()
17
+ @hypothTest3 = TwoSideTest.getInstance()
17
18
  end
18
19
  # T検定
19
20
  #
@@ -23,7 +24,7 @@ module Num4HypothTestLib
23
24
  # @param [double] a 有意水準
24
25
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
25
26
  def tDistTest(statistic, df, a)
26
- return @hypothTest.tDistTest(statistic, df, a)
27
+ return @hypothTest3.tDistTest(statistic, df, a)
27
28
  end
28
29
  # 階2乗検定
29
30
  #
@@ -33,7 +34,7 @@ module Num4HypothTestLib
33
34
  # @param [double] a 有意水準
34
35
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
35
36
  def chi2DistTest(statistic, df, a)
36
- return @hypothTest.chi2DistTest(statistic, df, a)
37
+ return @hypothTest3.chi2DistTest(statistic, df, a)
37
38
  end
38
39
  # 標準正規分布検定
39
40
  #
@@ -42,7 +43,7 @@ module Num4HypothTestLib
42
43
  # @param [double] a 有意水準
43
44
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
44
45
  def normDistTest(statistic, a)
45
- return @hypothTest.normDistTest(statistic, a)
46
+ return @hypothTest3.normDistTest(statistic, a)
46
47
  end
47
48
  # F検定
48
49
  #
@@ -53,26 +54,26 @@ module Num4HypothTestLib
53
54
  # @param [double] a 有意水準
54
55
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
55
56
  def fDistTest(statistic, nf, df, a)
56
- return @hypothTest.fDistTest(statistic, nf, df, a)
57
+ return @hypothTest3.fDistTest(statistic, nf, df, a)
57
58
  end
58
- # ウィルコクソン符号順位検定
59
+
60
+ # 母相関係数の検定量
59
61
  #
60
- # @overload wilcoxon(statistic, n, a)
61
- # @param [int] statistic ウィルコクソン符号順位の検定統計量
62
- # @param [int] n データの個数
63
- # @param [double] a 有意水準
62
+ # @overload populationCorre(r, n, rth0, a)
63
+ # @param [double] r 標本相関係数
64
+ # @param [int] n 自由度
65
+ # @param [double] rth0 母相関係数
64
66
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
65
67
  # @note
66
- # 内部でN(0,1)に近似して検定
67
- def wilcoxon(statistic, n, a)
68
- return @hypothTest.wilcoxon(statistic, n, a)
68
+ # 標準正規分布 N(0,1*1)に従う(近似的)
69
+ def populationCorre(r, n, rth0, a)
70
+ return @hypothTest3.populationCorre(r, n, rth0, a);
69
71
  end
70
-
71
72
  end
72
73
  # 片側(右側)検定
73
74
  class RightSideTestLib
74
75
  def initialize
75
- @hypothTest = RightSideTest.getInstance()
76
+ @hypothTest3 = RightSideTest.getInstance()
76
77
  end
77
78
  # T検定
78
79
  #
@@ -82,7 +83,7 @@ module Num4HypothTestLib
82
83
  # @param [double] a 有意水準
83
84
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
84
85
  def tDistTest(statistic, df, a)
85
- return @hypothTest.tDistTest(statistic, df, a)
86
+ return @hypothTest3.tDistTest(statistic, df, a)
86
87
  end
87
88
  # 階2乗検定
88
89
  #
@@ -92,7 +93,7 @@ module Num4HypothTestLib
92
93
  # @param [double] a 有意水準
93
94
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
94
95
  def chi2DistTest(statistic, df, a)
95
- return @hypothTest.chi2DistTest(statistic, df, a)
96
+ return @hypothTest3.chi2DistTest(statistic, df, a)
96
97
  end
97
98
  # 標準正規分布検定
98
99
  #
@@ -101,7 +102,7 @@ module Num4HypothTestLib
101
102
  # @param [double] a 有意水準
102
103
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
103
104
  def normDistTest(statistic, a)
104
- return @hypothTest.normDistTest(statistic, a)
105
+ return @hypothTest3.normDistTest(statistic, a)
105
106
  end
106
107
  # F検定
107
108
  #
@@ -112,25 +113,26 @@ module Num4HypothTestLib
112
113
  # @param [double] a 有意水準
113
114
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
114
115
  def fDistTest(statistic, nf, df, a)
115
- return @hypothTest.fDistTest(statistic, nf, df, a)
116
+ return @hypothTest3.fDistTest(statistic, nf, df, a)
116
117
  end
117
- # ウィルコクソン符号順位検定
118
+
119
+ # 母相関係数の検定量
118
120
  #
119
- # @overload wilcoxon(statistic, n, a)
120
- # @param [int] statistic ウィルコクソン符号順位の検定統計量
121
- # @param [int] n データの個数
122
- # @param [double] a 有意水準
121
+ # @overload populationCorre(r, n, rth0, a)
122
+ # @param [double] r 標本相関係数
123
+ # @param [int] n 自由度
124
+ # @param [double] rth0 母相関係数
123
125
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
124
126
  # @note
125
- # 内部でN(0,1)に近似して検定
126
- def wilcoxon(statistic, n, a)
127
- return @hypothTest.wilcoxon(statistic, n, a)
127
+ # 標準正規分布 N(0,1*1)に従う(近似的)
128
+ def populationCorre(r, n, rth0, a)
129
+ return @hypothTest3.populationCorre(r, n, rth0, a);
128
130
  end
129
131
  end
130
132
  # 片側(左側)検定
131
133
  class LeftSideTestLib
132
134
  def initialize
133
- @hypothTest = LeftSideTest.getInstance()
135
+ @hypothTest3 = LeftSideTest.getInstance()
134
136
  end
135
137
  # T検定
136
138
  #
@@ -140,7 +142,7 @@ module Num4HypothTestLib
140
142
  # @param [double] a 有意水準
141
143
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
142
144
  def tDistTest(statistic, df, a)
143
- return @hypothTest.tDistTest(statistic, df, a)
145
+ return @hypothTest3.tDistTest(statistic, df, a)
144
146
  end
145
147
  # 階2乗検定
146
148
  #
@@ -150,7 +152,7 @@ module Num4HypothTestLib
150
152
  # @param [double] a 有意水準
151
153
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
152
154
  def chi2DistTest(statistic, df, a)
153
- return @hypothTest.chi2DistTest(statistic, df, a)
155
+ return @hypothTest3.chi2DistTest(statistic, df, a)
154
156
  end
155
157
  # 標準正規分布検定
156
158
  #
@@ -159,7 +161,7 @@ module Num4HypothTestLib
159
161
  # @param [double] a 有意水準
160
162
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
161
163
  def normDistTest(statistic, a)
162
- return @hypothTest.normDistTest(statistic, a)
164
+ return @hypothTest3.normDistTest(statistic, a)
163
165
  end
164
166
  # F検定
165
167
  #
@@ -170,25 +172,26 @@ module Num4HypothTestLib
170
172
  # @param [double] a 有意水準
171
173
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
172
174
  def fDistTest(statistic, nf, df, a)
173
- return @hypothTest.fDistTest(statistic, nf, df, a)
175
+ return @hypothTest3.fDistTest(statistic, nf, df, a)
174
176
  end
175
- # ウィルコクソン符号順位検定
177
+
178
+ # 母相関係数の検定量
176
179
  #
177
- # @overload wilcoxon(statistic, n, a)
178
- # @param [int] statistic ウィルコクソン符号順位の検定統計量
179
- # @param [int] n データの個数
180
- # @param [double] a 有意水準
180
+ # @overload populationCorre(r, n, rth0, a)
181
+ # @param [double] r 標本相関係数
182
+ # @param [int] n 自由度
183
+ # @param [double] rth0 母相関係数
181
184
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
182
185
  # @note
183
- # 内部でN(0,1)に近似して検定
184
- def wilcoxon(statistic, n, a)
185
- return @hypothTest.wilcoxon(statistic, n, a)
186
+ # 標準正規分布 N(0,1*1)に従う(近似的)
187
+ def populationCorre(r, n, rth0, a)
188
+ return @hypothTest3.populationCorre(r, n, rth0, a);
186
189
  end
187
190
  end
188
191
  # グラブス・スミルノフの外れ値の検定
189
192
  class GrubbsTestLib
190
193
  def initialize
191
- @hypothTest = GrubbsTest.getInstance()
194
+ @hypothTest2 = GrubbsTest.getInstance()
192
195
  end
193
196
  # 両側検定
194
197
  #
@@ -198,7 +201,7 @@ module Num4HypothTestLib
198
201
  # @param [double] a 有意水準
199
202
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
200
203
  def twoSideTest(statistic, n, a)
201
- return @hypothTest.twoSideTest(statistic, n, a)
204
+ return @hypothTest2.twoSideTest(statistic, n, a)
202
205
  end
203
206
  # 片側検定
204
207
  #
@@ -208,7 +211,23 @@ module Num4HypothTestLib
208
211
  # @param [double] a 有意水準
209
212
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
210
213
  def oneSideTest(statistic, n, a)
211
- return @hypothTest.oneSideTest(statistic, n, a)
214
+ return @hypothTest2.oneSideTest(statistic, n, a)
215
+ end
216
+ end
217
+ # 無相関の検定
218
+ class DecorrTestLib
219
+ def initialize
220
+ @hypothTest = DecorrTest.getInstance()
221
+ end
222
+ # 両側検定
223
+ #
224
+ # @overload twoSideTest(r, n, a)
225
+ # @param [double] r 相関係数
226
+ # @param [int] n 自由度
227
+ # @param [double] a 有意水準
228
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
229
+ def twoSideTest(r, n, a)
230
+ return @hypothTest.twoSideTest(r, n, a)
212
231
  end
213
232
  end
214
233
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4hypothtst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-19 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -61,8 +61,11 @@ files:
61
61
  - Gemfile
62
62
  - LICENSE
63
63
  - Rakefile
64
+ - ext/num4hypothtst/hypothtst/DecorrTest.java
64
65
  - ext/num4hypothtst/hypothtst/GrubbsTest.java
65
66
  - ext/num4hypothtst/hypothtst/HypothTest.java
67
+ - ext/num4hypothtst/hypothtst/HypothTest2.java
68
+ - ext/num4hypothtst/hypothtst/HypothTest3.java
66
69
  - ext/num4hypothtst/hypothtst/LeftSideTest.java
67
70
  - ext/num4hypothtst/hypothtst/RightSideTest.java
68
71
  - ext/num4hypothtst/hypothtst/TwoSideTest.java