num4tststatistic2 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/corrtest.rb +151 -0
- data/lib/num4tststatistic2.rb +6 -138
- metadata +3 -3
- data/lib/decorrtest.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfd90c54dab3784be95fad71d373a338e24c17a41b0bb5ddde46e46d77a4e739
|
4
|
+
data.tar.gz: 6fa678137d1a9b7fa3336a8f61bdc3fe03d89cb67c6ece3ff5ddb27c5216cfb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ec74c474a5d8524ab8c18eac95b33ac5c0bc96241a8aa8dea2aa3a2bb41d633c90aad4561611f25f421b68af754b5ebae32ac08a1ceb73b0ae672a1c9714ef
|
7
|
+
data.tar.gz: 2520663599be76415a0fb3a6106d096f5697be92fdbf1371affff34ac4f9aa1b6da0f24e36c5ef7150e6cd2eec05d94207fd38be17a97552ab78326d3e583e6a
|
data/CHANGELOG.md
CHANGED
data/lib/corrtest.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'num4tststatistic'
|
2
|
+
require 'hypothTest3'
|
3
|
+
|
4
|
+
# 相関検定
|
5
|
+
module CorrTestLib
|
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
|
data/lib/num4tststatistic2.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'num4tststatistic'
|
2
2
|
require 'hypothTest3'
|
3
|
-
require_relative('decorrtest')
|
4
3
|
|
5
4
|
# 統計的仮説検定
|
6
5
|
module Num4TstStatistic2Lib
|
@@ -72,7 +71,7 @@ module Num4TstStatistic2Lib
|
|
72
71
|
end
|
73
72
|
# 2つの母平均の差の検定
|
74
73
|
#
|
75
|
-
# @overload
|
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.
|
84
|
+
# paraTest.diffPopulationVarMean(xi1, xi2, 0.05)
|
86
85
|
# => false
|
87
|
-
def
|
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 # 等分散性
|
@@ -343,143 +343,11 @@ module Num4TstStatistic2Lib
|
|
343
343
|
# @example
|
344
344
|
# xi = [3.4, 3.5, 3.3, 2.2, 3.3, 3.4, 3.6, 3.2]
|
345
345
|
# outlier = Num4TstStatistic2Lib::OutlierLib.new
|
346
|
-
# outlier.
|
346
|
+
# outlier.errbar("LDH", xi)
|
347
347
|
# => errbar.jpeg
|
348
348
|
def errbar(dname, xi)
|
349
349
|
@outlier.errbar(dname, xi)
|
350
350
|
end
|
351
351
|
end
|
352
352
|
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
|
353
|
+
|
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.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2024-05-08 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/
|
62
|
+
- lib/corrtest.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
|