num4tststatistic2 0.1.1 → 0.2.1

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: 60785711542acd092cb1688f03e95bb31b372dab71e52048ec6adec7fcc2bcf5
4
- data.tar.gz: fc3dd84abfa51c591061cde8e4ebad3e56985dbb0ae30928f8456a2488aa9c42
3
+ metadata.gz: 7959285c4da926ed687eb9d7292df6e49fdbf6e6f478f747060d4313b6b75a86
4
+ data.tar.gz: 26f6275766687e48dbd58ef413efc57edc2d29fea9bf200b9d8d845987f87fba
5
5
  SHA512:
6
- metadata.gz: bccb6876cf7adb09a192dd34faf6fbd4f29652974e1cced0ae49bde5e30ce19c9c9a171db5744e2cd4128a3bbaf2a9d56c43720825693348c056bfe84b81e68b
7
- data.tar.gz: 1f8c945bc94f924990b7451d809ed883c0e7dee6ab4b25ab1c08c822314d7a4c9e1a4ba5d8f0c749369efd319e579aedc83d3cd7c1abaa37dc54ea2acf69c9b3
6
+ metadata.gz: 97b33ebc741f49d7ac1e4b5ca9b9811d67458a5a58d1cb06353eca28422ea329d9656e402703f41a6a7f3a44ed93a5c31790d1e1cc4fff4c1add6a127af69220
7
+ data.tar.gz: d08688f8e75d54eafdda166e7b7055a008719a823bb2a62a0dc4f4c00fbc12aa166ef76d68fb1f07397c65eae762fead655613f4101ecbb5623b2857ab7028e0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.2.1] - 2024-05-15
6
+ ### change
7
+ - change module name to Num4CorrTestLib from CorrTestLib.
8
+
9
+ ## [0.1.2] - 2024-05-08
10
+
11
+ ### chg
12
+ - change function name from diffPopulationMean2 to diffPopulationVarMean
13
+
5
14
  ## [0.1.1] - 2024-05-06
6
15
 
7
16
  ### add
@@ -0,0 +1,151 @@
1
+ require 'num4tststatistic'
2
+ require 'hypothTest3'
3
+
4
+ # 相関検定
5
+ module Num4CorrTestLib
6
+ # 無相関の検定
7
+ class DecorrTestLib
8
+ def initialize
9
+ @corr = CorrStatisticLib.new
10
+ @hypothTest = Num4HypothTestLib::DecorrTestLib.new
11
+ end
12
+ # ピアソン相関係数
13
+ #
14
+ # @overload pearsoCorrelation(x, y, a)
15
+ # @param [Array] x xのデータ(double[])
16
+ # @param [Array] y yのデータ(double[])
17
+ # @param [double] a 有意水準
18
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
19
+ # @example
20
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
21
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
22
+ # corrTest = CorrTestLib::DecorrTestLib.new
23
+ # corrTest.pearsoCorrelation(x, y, 0.05)
24
+ # => true
25
+ def pearsoCorrelation(x, y, a)
26
+ df = x.size - 2
27
+ statistic = @corr.pearsoCorrelation(x, y)
28
+ return @hypothTest.twoSideTest(statistic, df, a)
29
+ end
30
+ # スピアマンの順位相関係数
31
+ #
32
+ # @overload spearmanscorr(x, y, a)
33
+ # @param [Array] x xのデータ(double[])
34
+ # @param [Array] y yのデータ(double[])
35
+ # @param [double] a 有意水準
36
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
37
+ # @example
38
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
39
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
40
+ # corrTest = CorrTestLib::DecorrTestLib.new
41
+ # corrTest.spearmanscorr(x, y, 0.05)
42
+ # => true
43
+ def spearmanscorr(x, y, a)
44
+ df = x.size - 2
45
+ statistic = @corr.spearmanscorr(x, y)
46
+ return @hypothTest.twoSideTest(statistic, df, a)
47
+ end
48
+ # ケンドールの順位相関係数
49
+ #
50
+ # @overload kendallscorr(x, y, a)
51
+ # @param [Array] x xのデータ(double[])
52
+ # @param [Array] y yのデータ(double[])
53
+ # @param [double] a 有意水準
54
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
55
+ # @example
56
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
57
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
58
+ # corrTest = CorrTestLib::DecorrTestLib.new
59
+ # corrTest.kendallscorr(x, y, 0.05)
60
+ # => false
61
+ def kendallscorr(x, y, a)
62
+ df = x.size - 2
63
+ statistic = @corr.kendallscorr(x, y)
64
+ return @hypothTest.twoSideTest(statistic, df, a)
65
+ end
66
+ end
67
+ # 母相関係数の検定
68
+ class CorreFactLib
69
+ def initialize(hypothTest3)
70
+ @hypothTest3 = hypothTest3
71
+ @corr = CorrStatisticLib.new
72
+ end
73
+ # ピアソン相関係数
74
+ #
75
+ # @overload pearsoCorrelation(x, y, rth0, a)
76
+ # @param [Array] x xのデータ(double[])
77
+ # @param [Array] y yのデータ(double[])
78
+ # @param [double] rth0 母相関係数
79
+ # @param [double] a 有意水準
80
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
81
+ # @example
82
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
83
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
84
+ # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
85
+ # corrTest = CorrTestLib::CorreFactLib.new(hypothTest)
86
+ # corrTest.pearsoCorrelation(x, y, -0.3, 0.05)
87
+ # => true
88
+ def pearsoCorrelation(x, y, rth0, a)
89
+ raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
90
+ statistic = @corr.pearsoCorrelation(x, y)
91
+ return @hypothTest3.populationCorre(statistic, x.size, rth0, a)
92
+ end
93
+ # スピアマンの順位相関係数
94
+ #
95
+ # @overload spearmanscorr(x, y, rth0, a)
96
+ # @param [Array] x xのデータ(double[])
97
+ # @param [Array] y yのデータ(double[])
98
+ # @param [double] rth0 母相関係数
99
+ # @param [double] a 有意水準
100
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
101
+ # @example
102
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
103
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
104
+ # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
105
+ # corrTest = CorrTestLib::CorreFactLib.new(hypothTest)
106
+ # corrTest.spearmanscorr(x, y, -0.3, 0.05)
107
+ # => true
108
+ def spearmanscorr(x, y, rth0, a)
109
+ raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
110
+ statistic = @corr.spearmanscorr(x, y)
111
+ return @hypothTest3.populationCorre(statistic, x.size, rth0, a)
112
+ end
113
+ # ケンドールの順位相関係数
114
+ #
115
+ # @overload kendallscorr(x, y, rth0, a)
116
+ # @param [Array] x xのデータ(double[])
117
+ # @param [Array] y yのデータ(double[])
118
+ # @param [double] rth0 母相関係数
119
+ # @param [double] a 有意水準
120
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
121
+ # @example
122
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
123
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
124
+ # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
125
+ # corrTest = CorrTestLib::CorreFactLib.new(hypothTest)
126
+ # corrTest.kendallscorr(x, y, -0.3, 0.05)
127
+ # => true
128
+ def kendallscorr(x, y, rth0, a)
129
+ raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
130
+ statistic = @corr.kendallscorr(x, y)
131
+ return @hypothTest3.populationCorre(statistic, x.size, rth0, a)
132
+ end
133
+ end
134
+
135
+ class CorrStatisticLib
136
+ def initialize
137
+ @paraTest = Num4TstStatisticLib::ParametrixTestLib.new
138
+ @nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
139
+ end
140
+ def pearsoCorrelation(x, y)
141
+ return @paraTest.pearsoCorrelation(x, y)
142
+ end
143
+ def spearmanscorr(x, y)
144
+ return @nonParaTest.spearmanscorr(x, y)
145
+ end
146
+ def kendallscorr(x, y)
147
+ return @nonParaTest.kendallscorr(x, y)
148
+ end
149
+ end
150
+ private_constant :CorrStatisticLib
151
+ end
@@ -1,6 +1,5 @@
1
1
  require 'num4tststatistic'
2
2
  require 'hypothTest3'
3
- require_relative('decorrtest')
4
3
 
5
4
  # 統計的仮説検定
6
5
  module Num4TstStatistic2Lib
@@ -70,9 +69,9 @@ module Num4TstStatistic2Lib
70
69
  statistic = @paraTest.populationRatio(m, n, p0)
71
70
  return @hypothTest3.normDistTest(statistic, a)
72
71
  end
73
- # 2つの母平均の差の検定
72
+ # 2つの母平均の差の検定(等分散性check有り)
74
73
  #
75
- # @overload diffPopulationMean2(xi1, xi2, a)
74
+ # @overload diffPopulationVarMean(xi1, xi2, a)
76
75
  # @param [Array] xi1 x1のデータ(double[])
77
76
  # @param [Array] xi2 x2のデータ(double[])
78
77
  # @param [double] a 有意水準
@@ -82,10 +81,11 @@ module Num4TstStatistic2Lib
82
81
  # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
83
82
  # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
84
83
  # paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
85
- # paraTest.diffPopulationMean2(xi1, xi2, 0.05)
84
+ # paraTest.diffPopulationVarMean(xi1, xi2, 0.05)
86
85
  # => false
87
- def diffPopulationMean2(xi1, xi2, a)
86
+ def diffPopulationVarMean(xi1, xi2, a)
88
87
  bRet = diffPopulationVar(xi1, xi2, a)
88
+
89
89
  if bRet == true # 等分散ではない
90
90
  return diffPopulationMean2UnEquVar(xi1, xi2, a)
91
91
  else # 等分散性
@@ -152,6 +152,7 @@ module Num4TstStatistic2Lib
152
152
  # => true
153
153
  def diffPopulationMean(xi1, xi2, a)
154
154
  raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
155
+ raise RangeError unless xi1.size == xi2.size
155
156
 
156
157
  n = xi1.size
157
158
  df = n - 1
@@ -343,143 +344,11 @@ module Num4TstStatistic2Lib
343
344
  # @example
344
345
  # xi = [3.4, 3.5, 3.3, 2.2, 3.3, 3.4, 3.6, 3.2]
345
346
  # outlier = Num4TstStatistic2Lib::OutlierLib.new
346
- # outlier.grubbs("LDH", xi)
347
+ # outlier.errbar("LDH", xi)
347
348
  # => errbar.jpeg
348
349
  def errbar(dname, xi)
349
350
  @outlier.errbar(dname, xi)
350
351
  end
351
352
  end
352
353
  end
353
- # 相関検定
354
- module DecorrTestLib
355
- # 無相関の検定
356
- class UnDecorrTestLib < DecorrTestIF
357
- def initialize
358
- @paraTest = Num4TstStatisticLib::ParametrixTestLib.new
359
- @nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
360
- @hypothTest = Num4HypothTestLib::DecorrTestLib.new
361
- end
362
- # ピアソン相関係数
363
- #
364
- # @overload pearsoCorrelation(x, y, a)
365
- # @param [Array] x xのデータ(double[])
366
- # @param [Array] y yのデータ(double[])
367
- # @param [double] a 有意水準
368
- # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
369
- # @example
370
- # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
371
- # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
372
- # decorrTest = DecorrTestLib::UnDecorrTestLib.new
373
- # decorrTest.pearsoCorrelation(x, y, 0.05)
374
- # => true
375
- def pearsoCorrelation(x, y, a)
376
- df = x.size - 2
377
- statistic = @paraTest.pearsoCorrelation(x, y)
378
- return @hypothTest.twoSideTest(statistic, df, a)
379
- end
380
- # スピアマンの順位相関係数
381
- #
382
- # @overload spearmanscorr(x, y, a)
383
- # @param [Array] x xのデータ(double[])
384
- # @param [Array] y yのデータ(double[])
385
- # @param [double] a 有意水準
386
- # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
387
- # @example
388
- # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
389
- # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
390
- # decorrTest = DecorrTestLib::UnDecorrTestLib.new
391
- # decorrTest.spearmanscorr(x, y, 0.05)
392
- # => true
393
- def spearmanscorr(x, y, a)
394
- df = x.size - 2
395
- statistic = @nonParaTest.spearmanscorr(x, y)
396
- return @hypothTest.twoSideTest(statistic, df, a)
397
- end
398
- # ケンドールの順位相関係数
399
- #
400
- # @overload kendallscorr(x, y, a)
401
- # @param [Array] x xのデータ(double[])
402
- # @param [Array] y yのデータ(double[])
403
- # @param [double] a 有意水準
404
- # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
405
- # @example
406
- # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
407
- # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
408
- # decorrTest = DecorrTestLib::UnDecorrTestLib.new
409
- # decorrTest.kendallscorr(x, y, 0.05)
410
- # => false
411
- def kendallscorr(x, y, a)
412
- df = x.size - 2
413
- statistic = @nonParaTest.kendallscorr(x, y)
414
- return @hypothTest.twoSideTest(statistic, df, a)
415
- end
416
- end
417
- # 相関係数の検定
418
- class CorreFactLib < CorreFactIF
419
- def initialize(hypothTest3)
420
- @hypothTest3 = hypothTest3
421
- @paraTest = Num4TstStatisticLib::ParametrixTestLib.new
422
- @nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
423
- end
424
- # ピアソン相関係数
425
- #
426
- # @overload pearsoCorrelation(x, y, rth0, a)
427
- # @param [Array] x xのデータ(double[])
428
- # @param [Array] y yのデータ(double[])
429
- # @param [double] rth0 母相関係数
430
- # @param [double] a 有意水準
431
- # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
432
- # @example
433
- # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
434
- # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
435
- # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
436
- # decorrTest = DecorrTestLib::CorreFactLib.new(hypothTest)
437
- # decorrTest.pearsoCorrelation(x, y, -0.3, 0.05)
438
- # => true
439
- def pearsoCorrelation(x, y, rth0, a)
440
- raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
441
- statistic = @paraTest.pearsoCorrelation(x, y)
442
- return @hypothTest3.populationCorre(statistic, x.size, rth0, a)
443
- end
444
- # スピアマンの順位相関係数
445
- #
446
- # @overload spearmanscorr(x, y, rth0, a)
447
- # @param [Array] x xのデータ(double[])
448
- # @param [Array] y yのデータ(double[])
449
- # @param [double] rth0 母相関係数
450
- # @param [double] a 有意水準
451
- # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
452
- # @example
453
- # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
454
- # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
455
- # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
456
- # decorrTest = DecorrTestLib::CorreFactLib.new(hypothTest)
457
- # decorrTest.spearmanscorr(x, y, -0.3, 0.05)
458
- # => true
459
- def spearmanscorr(x, y, rth0, a)
460
- raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
461
- statistic = @nonParaTest.spearmanscorr(x, y)
462
- return @hypothTest3.populationCorre(statistic, x.size, rth0, a)
463
- end
464
- # ケンドールの順位相関係数
465
- #
466
- # @overload kendallscorr(x, y, rth0, a)
467
- # @param [Array] x xのデータ(double[])
468
- # @param [Array] y yのデータ(double[])
469
- # @param [double] rth0 母相関係数
470
- # @param [double] a 有意水準
471
- # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
472
- # @example
473
- # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
474
- # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
475
- # hypothTest = Num4HypothTestLib::TwoSideTestLib.new
476
- # decorrTest = DecorrTestLib::CorreFactLib.new(hypothTest)
477
- # decorrTest.kendallscorr(x, y, -0.3, 0.05)
478
- # => true
479
- def kendallscorr(x, y, rth0, a)
480
- raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)
481
- statistic = @nonParaTest.kendallscorr(x, y)
482
- return @hypothTest3.populationCorre(statistic, x.size, rth0, a)
483
- end
484
- end
485
- end
354
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4tststatistic2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.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-06 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: num4tststatistic
@@ -59,7 +59,7 @@ files:
59
59
  - CHANGELOG.md
60
60
  - Gemfile
61
61
  - LICENSE
62
- - lib/decorrtest.rb
62
+ - lib/num4corrtest.rb
63
63
  - lib/num4tststatistic2.rb
64
64
  homepage: https://github.com/siranovel/num4tststatistic2
65
65
  licenses:
data/lib/decorrtest.rb DELETED
@@ -1,22 +0,0 @@
1
- class DecorrTestIF
2
- def pearsoCorrelation(x, y, a)
3
- raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません")
4
- end
5
- def spearmanscorr(x, y, a)
6
- raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません")
7
- end
8
- def kendallscorr(x, y, a)
9
- raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません")
10
- end
11
- end
12
- class CorreFactIF
13
- def pearsoCorrelation(x, y, rth0, a)
14
- raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません")
15
- end
16
- def spearmanscorr(x, y, rth0, a)
17
- raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません")
18
- end
19
- def kendallscorr(x, y, rth0, a)
20
- raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません")
21
- end
22
- end