num4hypothtst 0.0.3-java → 0.0.5-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: 6f3db78a057e9644f315ed9a66f7e8229e7b3d6f1c50a304be1ba18b5d4da0a0
4
- data.tar.gz: 34a09f03fbeb46c04e31565558f966de27c9cff12e1fb126033ec364dc056256
3
+ metadata.gz: c6ff3dd6e82c9be96c99627583dc57403f357a9fd7cfd47d20b4a9b91aa169ff
4
+ data.tar.gz: 52b8a0961a549a213d35e431b73b50935642a4f2ad5aa69cf05ca9637577b1bb
5
5
  SHA512:
6
- metadata.gz: 5d5f9dd8d576cdaefcd9bc91ad52d5d70e3efd96cbe2b26f07c67eaec350b0e738c9bec8cdca32d84c6bcfbb7056a878b8b0a795fede0ce20ca7fd4cfbd4f9a9
7
- data.tar.gz: fb835295a001d917844e17416d5c1fcf222bd9c3f719beb274fff2a7fcb9c77cdbd123c2c21cfb32cd135ee50f3586c5e70e89c5874857afbce25bcc0db7bca1
6
+ metadata.gz: 6da36a8c168a2a0055483738640ccecb5babb6d3268c109240e330a7cae3da486582dcef1271336402e2cba567911a2e0e59ef6c25c8963ef4428283be387821
7
+ data.tar.gz: 43af75b2187bdb1e4fce7202b5414cfd1534ab4246f30713cfa8ddee56457bbc4d03ebb5a5ca0ca4d271a32acba2512877fe8b70974a6db7eefa2190ebf79d2e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.5] - 2023-12-19
6
+
7
+ ### add
8
+ - add function of wilcoxon.
9
+
10
+ ## [0.0.4] - 2023-10-13
11
+
12
+ ### change
13
+ - chg gnTest
14
+
5
15
  ## [0.0.3] - 2023-10-05
6
16
 
7
17
  ### change
@@ -0,0 +1,34 @@
1
+ package hypothtst;
2
+
3
+ import org.apache.commons.math3.distribution.TDistribution;
4
+ // グラブス・スミルノフの外れ値の検定
5
+ public class GrubbsTest {
6
+ private static GrubbsTest grubbs = new GrubbsTest();
7
+ public static GrubbsTest getInstance() {
8
+ return grubbs;
9
+ }
10
+ public boolean twoSideTest(double statistic, int n, double a) {
11
+ double r_val = calcGnValue(n, a / 2.0);
12
+ return evaluation(statistic, r_val);
13
+ }
14
+ public boolean oneSideTest(double statistic, int n, double a) {
15
+ double r_val = calcGnValue(n, a);
16
+ return evaluation(statistic, r_val);
17
+ }
18
+ private double calcGnValue(int n, double a) {
19
+ TDistribution tDist = new TDistribution(n);
20
+ double t = tDist.inverseCumulativeProbability(a / n);
21
+ double gn = (n - 1) * t / Math.sqrt(n * (n - 2 + t * t));
22
+
23
+ return Math.abs(gn);
24
+ }
25
+ private boolean evaluation(double statistic, double r_val) {
26
+ boolean ret = true;
27
+
28
+ if (Math.abs(statistic) < r_val) {
29
+ ret = false;
30
+ }
31
+ return ret;
32
+ }
33
+ }
34
+
@@ -1,9 +1,11 @@
1
+ package hypothtst;
2
+
1
3
  // 仮設検定
2
4
  interface HypothTest {
3
5
  boolean tDistTest(double statistic, double df, double a);
4
6
  boolean chi2DistTest(double statistic, double df, double a);
5
7
  boolean normDistTest(double statistic, double a);
6
8
  boolean fDistTest(double statistic, double nf, double df, double a);
7
- boolean gnTest(double statistic, int n, double a);
9
+ boolean wilcoxon(double statistic, int n, double a);
8
10
  }
9
11
 
@@ -1,9 +1,11 @@
1
- // 片側検定(左側)
1
+ package hypothtst;
2
+
2
3
  import org.apache.commons.math3.distribution.TDistribution;
3
4
  import org.apache.commons.math3.distribution.ChiSquaredDistribution;
4
5
  import org.apache.commons.math3.distribution.NormalDistribution;
5
6
  import org.apache.commons.math3.distribution.FDistribution;
6
7
 
8
+ // 片側検定(左側)
7
9
  public class LeftSideTest implements HypothTest {
8
10
  private static HypothTest hupothTest = new LeftSideTest();
9
11
  public static HypothTest getInstance() {
@@ -33,8 +35,13 @@ public class LeftSideTest implements HypothTest {
33
35
 
34
36
  return evaluation(statistic, l_val);
35
37
  }
36
- public boolean gnTest(double statistic, int n, double a) {
37
- return false;
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
45
  }
39
46
 
40
47
  private boolean evaluation(double statistic, double l_val) {
@@ -1,8 +1,10 @@
1
+ package hypothtst;
2
+
1
3
  import org.apache.commons.math3.distribution.TDistribution;
2
4
  import org.apache.commons.math3.distribution.ChiSquaredDistribution;
3
5
  import org.apache.commons.math3.distribution.NormalDistribution;
4
6
  import org.apache.commons.math3.distribution.FDistribution;
5
-
7
+ // 片側検定(右側)
6
8
  public class RightSideTest implements HypothTest {
7
9
  private static HypothTest hupothTest = new RightSideTest();
8
10
  public static HypothTest getInstance() {
@@ -32,16 +34,13 @@ public class RightSideTest implements HypothTest {
32
34
 
33
35
  return evaluation(statistic, r_val);
34
36
  }
35
- public boolean gnTest(double statistic, int n, double a) {
36
- double r_val = calcGnValue(n, a);
37
- return evaluation(statistic, r_val);
38
- }
39
- private double calcGnValue(int n, double a) {
40
- TDistribution tDist = new TDistribution(n);
41
- double t = tDist.inverseCumulativeProbability(a / n);
42
- double gn = (n - 1) * t / Math.sqrt(n * (n - 2 + t * t));
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);
43
42
 
44
- return Math.abs(gn);
43
+ return normDistTest(z, a);
45
44
  }
46
45
  private boolean evaluation(double statistic, double r_val) {
47
46
  boolean ret = true;
@@ -1,9 +1,11 @@
1
- // 両側検定
1
+ package hypothtst;
2
+
2
3
  import org.apache.commons.math3.distribution.TDistribution;
3
4
  import org.apache.commons.math3.distribution.ChiSquaredDistribution;
4
5
  import org.apache.commons.math3.distribution.NormalDistribution;
5
6
  import org.apache.commons.math3.distribution.FDistribution;
6
7
 
8
+ // 両側検定
7
9
  public class TwoSideTest implements HypothTest {
8
10
  private static HypothTest hupothTest = new TwoSideTest();
9
11
  public static HypothTest getInstance() {
@@ -37,17 +39,15 @@ public class TwoSideTest implements HypothTest {
37
39
 
38
40
  return evaluation(statistic, l_val, r_val);
39
41
  }
40
- public boolean gnTest(double statistic, int n, double a) {
41
- double r_val = calcGnValue(n, a / 2.0);
42
- return evaluation(statistic, r_val);
43
- }
44
- private double calcGnValue(int n, double a) {
45
- TDistribution tDist = new TDistribution(n);
46
- double t = tDist.inverseCumulativeProbability(a / n);
47
- double gn = (n - 1) * t / Math.sqrt(n * (n - 2 + t * t));
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);
48
47
 
49
- return Math.abs(gn);
48
+ return normDistTest(z, a);
50
49
  }
50
+
51
51
  private boolean evaluation(double statistic, double l_val, double r_val) {
52
52
  boolean ret = true;
53
53
 
@@ -56,14 +56,6 @@ public class TwoSideTest implements HypothTest {
56
56
  }
57
57
  return ret;
58
58
  }
59
- private boolean evaluation(double statistic, double r_val) {
60
- boolean ret = true;
61
-
62
- if (Math.abs(statistic) < r_val) {
63
- ret = false;
64
- }
65
- return ret;
66
- }
67
59
 
68
60
  }
69
61
 
data/lib/num4hypothtst.rb CHANGED
@@ -2,9 +2,10 @@ require 'java'
2
2
  require 'num4hypothtst.jar'
3
3
  require 'commons-math3-3.6.1.jar'
4
4
 
5
- java_import 'TwoSideTest'
6
- java_import 'RightSideTest'
7
- java_import 'LeftSideTest'
5
+ java_import 'hypothtst.TwoSideTest'
6
+ java_import 'hypothtst.RightSideTest'
7
+ java_import 'hypothtst.LeftSideTest'
8
+ java_import 'hypothtst.GrubbsTest'
8
9
 
9
10
  # 統計的仮設検定のためのライブラリ
10
11
  # (Apache commoms math3使用)
@@ -54,16 +55,19 @@ module Num4HypothTestLib
54
55
  def fDistTest(statistic, nf, df, a)
55
56
  return @hypothTest.fDistTest(statistic, nf, df, a)
56
57
  end
57
- # グラブス・スミルノフの外れ値の検定
58
+ # ウィルコクソン符号順位検定
58
59
  #
59
- # @overload gnTest(statistic, n, a)
60
- # @param [double] statistic 検定統計量
61
- # @param [int] n 自由度
60
+ # @overload wilcoxon(statistic, n, a)
61
+ # @param [int] statistic ウィルコクソン符号順位の検定統計量
62
+ # @param [int] n データの個数
62
63
  # @param [double] a 有意水準
63
64
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
64
- def gnTest(statistic, n, a)
65
- return @hypothTest.gnTest(statistic, n, a)
65
+ # @note
66
+ # 内部でN(0,1)に近似して検定
67
+ def wilcoxon(statistic, n, a)
68
+ return @hypothTest.wilcoxon(statistic, n, a)
66
69
  end
70
+
67
71
  end
68
72
  # 片側(右側)検定
69
73
  class RightSideTestLib
@@ -110,15 +114,17 @@ module Num4HypothTestLib
110
114
  def fDistTest(statistic, nf, df, a)
111
115
  return @hypothTest.fDistTest(statistic, nf, df, a)
112
116
  end
113
- # グラブス・スミルノフの外れ値の検定
117
+ # ウィルコクソン符号順位検定
114
118
  #
115
- # @overload gnTest(statistic, n, a)
116
- # @param [double] statistic 検定統計量
117
- # @param [int] n 自由度
119
+ # @overload wilcoxon(statistic, n, a)
120
+ # @param [int] statistic ウィルコクソン符号順位の検定統計量
121
+ # @param [int] n データの個数
118
122
  # @param [double] a 有意水準
119
123
  # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
120
- def gnTest(statistic, n, a)
121
- return @hypothTest.gnTest(statistic, n, a)
124
+ # @note
125
+ # 内部でN(0,1)に近似して検定
126
+ def wilcoxon(statistic, n, a)
127
+ return @hypothTest.wilcoxon(statistic, n, a)
122
128
  end
123
129
  end
124
130
  # 片側(左側)検定
@@ -166,6 +172,44 @@ module Num4HypothTestLib
166
172
  def fDistTest(statistic, nf, df, a)
167
173
  return @hypothTest.fDistTest(statistic, nf, df, a)
168
174
  end
175
+ # ウィルコクソン符号順位検定
176
+ #
177
+ # @overload wilcoxon(statistic, n, a)
178
+ # @param [int] statistic ウィルコクソン符号順位の検定統計量
179
+ # @param [int] n データの個数
180
+ # @param [double] a 有意水準
181
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
182
+ # @note
183
+ # 内部でN(0,1)に近似して検定
184
+ def wilcoxon(statistic, n, a)
185
+ return @hypothTest.wilcoxon(statistic, n, a)
186
+ end
187
+ end
188
+ # グラブス・スミルノフの外れ値の検定
189
+ class GrubbsTestLib
190
+ def initialize
191
+ @hypothTest = GrubbsTest.getInstance()
192
+ end
193
+ # 両側検定
194
+ #
195
+ # @overload twoSideTest(statistic, n, a)
196
+ # @param [double] statistic 検定統計量
197
+ # @param [int] n 自由度
198
+ # @param [double] a 有意水準
199
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
200
+ def twoSideTest(statistic, n, a)
201
+ return @hypothTest.twoSideTest(statistic, n, a)
202
+ end
203
+ # 片側検定
204
+ #
205
+ # @overload oneSideTest(statistic, n, a)
206
+ # @param [double] statistic 検定統計量
207
+ # @param [int] n 自由度
208
+ # @param [double] a 有意水準
209
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
210
+ def oneSideTest(statistic, n, a)
211
+ return @hypothTest.oneSideTest(statistic, n, a)
212
+ end
169
213
  end
170
214
  end
171
215
 
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.3
4
+ version: 0.0.5
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-05 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -61,10 +61,11 @@ files:
61
61
  - Gemfile
62
62
  - LICENSE
63
63
  - Rakefile
64
- - ext/num4hypothtst/HypothTest.java
65
- - ext/num4hypothtst/LeftSideTest.java
66
- - ext/num4hypothtst/RightSideTest.java
67
- - ext/num4hypothtst/TwoSideTest.java
64
+ - ext/num4hypothtst/hypothtst/GrubbsTest.java
65
+ - ext/num4hypothtst/hypothtst/HypothTest.java
66
+ - ext/num4hypothtst/hypothtst/LeftSideTest.java
67
+ - ext/num4hypothtst/hypothtst/RightSideTest.java
68
+ - ext/num4hypothtst/hypothtst/TwoSideTest.java
68
69
  - lib/commons-math3-3.6.1.jar
69
70
  - lib/num4hypothtst.rb
70
71
  homepage: http://github.com/siranovel/num4hypothtst