num4tststatistic2 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/decorrtest.rb +22 -0
- data/lib/num4tststatistic2.rb +104 -8
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60785711542acd092cb1688f03e95bb31b372dab71e52048ec6adec7fcc2bcf5
|
4
|
+
data.tar.gz: fc3dd84abfa51c591061cde8e4ebad3e56985dbb0ae30928f8456a2488aa9c42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bccb6876cf7adb09a192dd34faf6fbd4f29652974e1cced0ae49bde5e30ce19c9c9a171db5744e2cd4128a3bbaf2a9d56c43720825693348c056bfe84b81e68b
|
7
|
+
data.tar.gz: 1f8c945bc94f924990b7451d809ed883c0e7dee6ab4b25ab1c08c822314d7a4c9e1a4ba5d8f0c749369efd319e579aedc83d3cd7c1abaa37dc54ea2acf69c9b3
|
data/CHANGELOG.md
CHANGED
data/lib/decorrtest.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
data/lib/num4tststatistic2.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'num4tststatistic'
|
2
2
|
require 'hypothTest3'
|
3
|
+
require_relative('decorrtest')
|
3
4
|
|
4
5
|
# 統計的仮説検定
|
5
6
|
module Num4TstStatistic2Lib
|
7
|
+
# パラメトリック検定
|
6
8
|
class ParametrixTestLib
|
7
9
|
def initialize(hypothTest3)
|
8
10
|
@hypothTest3 = hypothTest3
|
@@ -68,6 +70,28 @@ module Num4TstStatistic2Lib
|
|
68
70
|
statistic = @paraTest.populationRatio(m, n, p0)
|
69
71
|
return @hypothTest3.normDistTest(statistic, a)
|
70
72
|
end
|
73
|
+
# 2つの母平均の差の検定
|
74
|
+
#
|
75
|
+
# @overload diffPopulationMean2(xi1, xi2, a)
|
76
|
+
# @param [Array] xi1 x1のデータ(double[])
|
77
|
+
# @param [Array] xi2 x2のデータ(double[])
|
78
|
+
# @param [double] a 有意水準
|
79
|
+
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
80
|
+
# @example
|
81
|
+
# xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
|
82
|
+
# xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
|
83
|
+
# hypothTest = Num4HypothTestLib::TwoSideTestLib.new
|
84
|
+
# paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
|
85
|
+
# paraTest.diffPopulationMean2(xi1, xi2, 0.05)
|
86
|
+
# => false
|
87
|
+
def diffPopulationMean2(xi1, xi2, a)
|
88
|
+
bRet = diffPopulationVar(xi1, xi2, a)
|
89
|
+
if bRet == true # 等分散ではない
|
90
|
+
return diffPopulationMean2UnEquVar(xi1, xi2, a)
|
91
|
+
else # 等分散性
|
92
|
+
return diffPopulationMean2EquVar(xi1, xi2, a)
|
93
|
+
end
|
94
|
+
end
|
71
95
|
# 2つの母平均の差の検定(等分散性を仮定)
|
72
96
|
#
|
73
97
|
# @overload diffPopulationMean2EquVar(xi1, xi2, a)
|
@@ -222,6 +246,7 @@ module Num4TstStatistic2Lib
|
|
222
246
|
return @hypothTest3.chi2DistTest(statistic, df, a)
|
223
247
|
end
|
224
248
|
end
|
249
|
+
# ノンパラメトリック検定
|
225
250
|
class NonParametrixTestLib
|
226
251
|
def initialize(hypothTest3)
|
227
252
|
@hypothTest3 = hypothTest3
|
@@ -287,6 +312,7 @@ module Num4TstStatistic2Lib
|
|
287
312
|
return @nonParaTest.ks2test(xi1, xi2, a)
|
288
313
|
end
|
289
314
|
end
|
315
|
+
# 外れ値検定
|
290
316
|
class OutlierLib
|
291
317
|
def initialize
|
292
318
|
@outlier = Num4TstStatisticLib::OutlierLib.new
|
@@ -323,8 +349,11 @@ module Num4TstStatistic2Lib
|
|
323
349
|
@outlier.errbar(dname, xi)
|
324
350
|
end
|
325
351
|
end
|
352
|
+
end
|
353
|
+
# 相関検定
|
354
|
+
module DecorrTestLib
|
326
355
|
# 無相関の検定
|
327
|
-
class
|
356
|
+
class UnDecorrTestLib < DecorrTestIF
|
328
357
|
def initialize
|
329
358
|
@paraTest = Num4TstStatisticLib::ParametrixTestLib.new
|
330
359
|
@nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
|
@@ -340,8 +369,8 @@ module Num4TstStatistic2Lib
|
|
340
369
|
# @example
|
341
370
|
# x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
|
342
371
|
# y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
|
343
|
-
#
|
344
|
-
#
|
372
|
+
# decorrTest = DecorrTestLib::UnDecorrTestLib.new
|
373
|
+
# decorrTest.pearsoCorrelation(x, y, 0.05)
|
345
374
|
# => true
|
346
375
|
def pearsoCorrelation(x, y, a)
|
347
376
|
df = x.size - 2
|
@@ -358,8 +387,8 @@ module Num4TstStatistic2Lib
|
|
358
387
|
# @example
|
359
388
|
# x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
|
360
389
|
# y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
|
361
|
-
#
|
362
|
-
#
|
390
|
+
# decorrTest = DecorrTestLib::UnDecorrTestLib.new
|
391
|
+
# decorrTest.spearmanscorr(x, y, 0.05)
|
363
392
|
# => true
|
364
393
|
def spearmanscorr(x, y, a)
|
365
394
|
df = x.size - 2
|
@@ -376,8 +405,8 @@ module Num4TstStatistic2Lib
|
|
376
405
|
# @example
|
377
406
|
# x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
|
378
407
|
# y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
|
379
|
-
#
|
380
|
-
#
|
408
|
+
# decorrTest = DecorrTestLib::UnDecorrTestLib.new
|
409
|
+
# decorrTest.kendallscorr(x, y, 0.05)
|
381
410
|
# => false
|
382
411
|
def kendallscorr(x, y, a)
|
383
412
|
df = x.size - 2
|
@@ -385,5 +414,72 @@ module Num4TstStatistic2Lib
|
|
385
414
|
return @hypothTest.twoSideTest(statistic, df, a)
|
386
415
|
end
|
387
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
|
388
485
|
end
|
389
|
-
|
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.
|
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-
|
11
|
+
date: 2024-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: num4tststatistic
|
@@ -59,8 +59,9 @@ files:
|
|
59
59
|
- CHANGELOG.md
|
60
60
|
- Gemfile
|
61
61
|
- LICENSE
|
62
|
+
- lib/decorrtest.rb
|
62
63
|
- lib/num4tststatistic2.rb
|
63
|
-
homepage:
|
64
|
+
homepage: https://github.com/siranovel/num4tststatistic2
|
64
65
|
licenses:
|
65
66
|
- MIT
|
66
67
|
metadata: {}
|