num4difftest 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/lib/num4difftest.rb +200 -2
  4. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f8ad606198ba54c903c5abdc5d61e6ee8380d8cf9e521c9988fde3c82cbb5fb
4
- data.tar.gz: c6ae9112de403c5ab9d9542f25148c9198f2902e2620f712d9d8b218af3509a2
3
+ metadata.gz: f5e442258535f8d8041dc868158981992433299290bd9e81ee1386591f40a974
4
+ data.tar.gz: 4faca6d3ae6349a2057e7e5be289bc0e21904c5890d50523c2b257b295e27d91
5
5
  SHA512:
6
- metadata.gz: 1665eb7aafff3dd89ff24883cc4739125813b032f7eabbbab768986dca38677cd43a85458c4f6a034d751f1c27856762b434b2c1d8af82cc2354de330f9ca232
7
- data.tar.gz: e340acee6861096e77f0c5b7e5845035198f0b927e96ac0f8255e6442e08876cba00b351c9fb627c93c1153cd23ba2f60401cf9130cddf7b04e64afca71c02ac
6
+ metadata.gz: b7c0642d7c4f939fae24d461b254798ea598a5cbfc8d8225b17c8b7bafa9378f6b1b8a99734451c4a4de67634256fae0c6531d3176001b1311688933b8744cd0
7
+ data.tar.gz: dd85e95ffdf9f19d440aa019d9560c158569c7fb41e11790285316bd29ffcb8bcdf40b258c1d26d3bc549e072fe972aa4dd22da1b70fd1990993182795798e3c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.1.1] - 2024-06-17
6
+ ### add
7
+ - add function of mult2_diff_test and ancova_test in ParametrixTestLib.
8
+ - add function of mult2_diff_test in NonParametrixTestLib.
9
+
10
+ ## [0.0.2] - 2024-05-18
11
+ ### chg
12
+ - chg file of Gemfile and gemspec .
13
+
5
14
  ## [0.0.1] - 2024-05-18
6
15
 
7
16
  ### Fixed
data/lib/num4difftest.rb CHANGED
@@ -2,6 +2,7 @@ require 'num4tststatistic2'
2
2
  require 'hypothTest3'
3
3
  require 'num4anova'
4
4
 
5
+ # 母平均の差の検定
5
6
  module Num4DiffTestLib
6
7
  # パラメトリック検定
7
8
  class ParametrixTestLib
@@ -10,7 +11,22 @@ module Num4DiffTestLib
10
11
  @paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(@hypothTest3)
11
12
  @oneWay = Num4AnovaLib::OneWayLayoutLib.new
12
13
  @twoWay = Num4AnovaLib::TwoWayLayoutLib.new
14
+ @ancova = Num4AnovaLib::Num4AncovaLib.new
13
15
  end
16
+ # 2群の母平均の差の検定
17
+ #
18
+ # @overload smple_diff_test(xi1, xi2, a)
19
+ # @param [Array] xi1 データ(double[])
20
+ # @param [Array] xi2 データ(double[])
21
+ # @param [double] a 有意水準
22
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
23
+ # @example
24
+ # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
25
+ # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
26
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
27
+ # paraTest2 = Num4DiffTestLib::ParametrixTestLib.new(hypothTest2)
28
+ # paraTest2.smple_diff_test(xi1, xi2, 0.05)
29
+ # => false
14
30
  def smple_diff_test(xi1, xi2, a)
15
31
  raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
16
32
 
@@ -20,11 +36,141 @@ module Num4DiffTestLib
20
36
  return @paraTest.diffPopulationVarMean(xi1, xi2, a)
21
37
  end
22
38
  end
23
- def mult_diff_test(xi1, a)
39
+ # 3群以上の母平均の差の検定(1元配置)
40
+ #
41
+ # @overload mult_diff_test(xi1, a)
42
+ # @param [Array] xi1 データ(double[][])
43
+ # @param [double] a 有意水準
44
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
45
+ # @example
46
+ # xi = [
47
+ # [12.2, 18.8, 18.2],
48
+ # [22.2, 20.5, 14.6],
49
+ # [20.8, 19.5, 26.3],
50
+ # [26.4, 32.5, 31.3],
51
+ # [24.5, 21.2, 22.4],
52
+ # ]
53
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
54
+ # paraTest2 = Num4DiffTestLib::ParametrixTestLib.new(hypothTest2)
55
+ # paraTest2.mult_diff_test(xi, 0.05)
56
+ # => false
57
+ def mult_diff_test(xi, a)
24
58
  raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
25
59
 
26
- return @oneWay.oneway_anova(xi1, a)
60
+ if true == isReplicate(xi) then
61
+ return @oneWay.replicate_test(xi, a)
62
+ else
63
+ return @oneWay.oneway_anova(xi, a)
64
+ end
65
+ end
66
+ # 3群以上の母平均の差の検定(2元配置)
67
+ #
68
+ # @overload mult2_diff_test(xij, a)
69
+ # @param [Array] xi1 データ(double[][][] or double[][])
70
+ # @param [double] a 有意水準
71
+ # @return [Array] 検定結果(boolean[] true:棄却域内 false:棄却域外)
72
+ # @example
73
+ # xij = [
74
+ # [
75
+ # [13.2, 15.7, 11.9],
76
+ # [16.1, 15.7, 15.1],
77
+ # [9.1, 10.3, 8.2],
78
+ # ],
79
+ # [
80
+ # [22.8, 25.7, 18.5],
81
+ # [24.5, 21.2, 24.2],
82
+ # [11.9, 14.3, 13.7],
83
+ # ],
84
+ # [
85
+ # [21.8, 26.3, 32.1],
86
+ # [26.9, 31.3, 28.3],
87
+ # [15.1, 13.6, 16.2],
88
+ # ],
89
+ # [
90
+ # [25.7, 28.8, 29.5],
91
+ # [30.1, 33.8, 29.6],
92
+ # [15.2, 17.3, 14.8],
93
+ # ],
94
+ # ]
95
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
96
+ # paraTest2 = Num4DiffTestLib::ParametrixTestLib.new(hypothTest2)
97
+ # paraTest2.mult2_diff_test(xij, 0.05)
98
+ # =>
99
+ # res = [true, true]
100
+ def mult2_diff_test(xi1, a)
101
+ raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
102
+
103
+ xij = xi1
104
+ n = getDimNum(xi1, 0)
105
+ if n == 3 then # 繰り返しのあるデータ
106
+ res = @twoWay.twoway_anova(xi1, a)
107
+ if res[2] == true then
108
+ xij = @twoWay.create_oneway(xi1).to_a
109
+ end
110
+ end
111
+ res2 = @twoWay.twoway2_anova(xij, a)
112
+ return res2
27
113
  end
114
+ # 共分散分析
115
+ #
116
+ # @overload ancova_test(yi, xi, a)
117
+ # @param [Array] yi データ(double[][])
118
+ # @param [Array] xi データ(double[][])
119
+ # @param [double] a 有意水準
120
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
121
+ # @example
122
+ # yi = [
123
+ # [3, 5, 3],
124
+ # [3, 3, 8],
125
+ # [2, 2, 2],
126
+ # [3, 4, 2],
127
+ # [1, 2, 0],
128
+ # ]
129
+ # xi = [
130
+ # [35, 38, 39],
131
+ # [36, 39, 54],
132
+ # [40, 45, 39],
133
+ # [47, 52, 48],
134
+ # [64, 80, 70],
135
+ # ]
136
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
137
+ # paraTest2 = Num4DiffTestLib::ParametrixTestLib.new(hypothTest2)
138
+ # paraTest2.ancova_test(yi, xi, 0.05)
139
+ # => true
140
+ def ancova_test(yi, xi, a)
141
+ # 回帰直線の平行性検定
142
+ # (false: 平行)
143
+ if false != @ancova.parallel_test(yi, xi, a) then
144
+ return mult_diff_test(xi, a)
145
+ end
146
+ # 回帰直線の有意性検定
147
+ # (false: β=0)
148
+ if true != @ancova.significance_test(yi, xi, a) then
149
+ return mult_diff_test(xi, a)
150
+ end
151
+ # 水準間の差の検定
152
+ return @ancova.difference_test(yi, xi, a)
153
+ end
154
+
155
+ def getDimNum(xij, n)
156
+ return n unless xij.kind_of?(Array)
157
+ n += 1
158
+ getDimNum(xij[0], n)
159
+ end
160
+ def isReplicate(xij)
161
+ ret = true
162
+ n = xij.size
163
+ n0 = xij[0].size
164
+ n.times do |i|
165
+ if n0 != xij[i].size then
166
+ ret = false
167
+ end
168
+ end
169
+ return ret
170
+ end
171
+
172
+ private :getDimNum
173
+ private :isReplicate
28
174
  end
29
175
  # ノンパラメトリック検定
30
176
  class NonParametrixTestLib
@@ -34,6 +180,20 @@ module Num4DiffTestLib
34
180
  @oneWay = Num4AnovaLib::OneWayLayoutLib.new
35
181
  @twoWay = Num4AnovaLib::TwoWayLayoutLib.new
36
182
  end
183
+ # 2群の母平均の差の検定
184
+ #
185
+ # @overload smple_diff_test(xi1, xi2, a)
186
+ # @param [Array] xi1 データ(double[])
187
+ # @param [Array] xi2 データ(double[])
188
+ # @param [double] a 有意水準
189
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
190
+ # @example
191
+ # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
192
+ # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
193
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
194
+ # nonParaTest = Num4DiffTestLib::NonParametrixTestLib.new(hypothTest2)
195
+ # nonParaTest.smple_diff_test(xi1, xi2, 0.05)
196
+ # => false
37
197
  def smple_diff_test(xi1, xi2, a)
38
198
  raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
39
199
 
@@ -43,11 +203,49 @@ module Num4DiffTestLib
43
203
  return @nonParaTest.utest(xi1, xi2, a)
44
204
  end
45
205
  end
206
+ # 3群以上の母平均の差の検定(1元配置)
207
+ #
208
+ # @overload mult_diff_test(xi1, a)
209
+ # @param [Array] xi1 データ(double[][])
210
+ # @param [double] a 有意水準
211
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
212
+ # @example
213
+ # xi = [
214
+ # [12.2, 18.8, 18.2],
215
+ # [22.2, 20.5, 14.6, 20.8, 19.5, 26.3],
216
+ # [26.4, 32.5, 31.3, 24.5, 21.2, 22.4],
217
+ # ]
218
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
219
+ # nonParaTest = Num4DiffTestLib::NonParametrixTestLib.new(hypothTest2)
220
+ # nonParaTest.mult_diff_test(xi, 0.05)
221
+ # => false
46
222
  def mult_diff_test(xi1, a)
47
223
  raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
48
224
 
49
225
  return @oneWay.kruskalwallis_test(xi1, a)
50
226
  end
227
+ # 3群以上の母平均の差の検定(2元配置)
228
+ #
229
+ # @overload mult2_diff_test(xij, a)
230
+ # @param [Array] xi1 データ(double[][][] or double[][])
231
+ # @param [double] a 有意水準
232
+ # @return [Array] 検定結果(boolean[] true:棄却域内 false:棄却域外)
233
+ # @example
234
+ # xij = [
235
+ # [13.6, 15.6, 9.2],
236
+ # [22.3, 23.3, 13.3],
237
+ # [26.7, 28.8, 15.0],
238
+ # [28.0, 31.2, 15.8],
239
+ # ]
240
+ # hypothTest2 = Num4HypothTestLib::TwoSideTestLib.new
241
+ # nonParaTest = Num4DiffTestLib::NonParametrixTestLib.new(hypothTest2)
242
+ # nonParaTest.mult2_diff_test(xij, a)
243
+ # => true
244
+ def mult2_diff_test(xij, a)
245
+ raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
246
+
247
+ return @twoWay.friedman_test(xij, a)
248
+ end
51
249
  end
52
250
  end
53
251
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4difftest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-18 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -20,7 +20,7 @@ dependencies:
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.2.1
22
22
  name: num4tststatistic2
23
- type: :development
23
+ type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
@@ -35,21 +35,21 @@ dependencies:
35
35
  requirements:
36
36
  - - "~>"
37
37
  - !ruby/object:Gem::Version
38
- version: '0.1'
38
+ version: '0.2'
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 0.1.1
41
+ version: 0.2.1
42
42
  name: num4anova
43
- type: :development
43
+ type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0.1'
49
+ version: '0.2'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.1.1
52
+ version: 0.2.1
53
53
  description: test of difference of population mean.
54
54
  email: siranovel@gmail.com
55
55
  executables: []