ruby-statistics 2.0.1 → 2.0.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 +5 -5
- data/lib/statistics/statistical_test/t_test.rb +16 -1
- data/lib/statistics/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8acc3f5b58158ceacc6f135095810d06e001808af321be98a58e341890cdbf12
|
4
|
+
data.tar.gz: 6e71f846819896c499afe4268ac836f1a57be655ef0df35019d4e99cd52a90a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d71ff94c0fca0a0eb439a82b9392926f8c96234e76b687200e3ad2a25183a5226dfc294f96a4cec892c4143c5faf3753cacb38da597d1d3d063858db16213cb
|
7
|
+
data.tar.gz: 6264ff4088fc85f2c718b1404dc18f27012c7761f42ac6174e7810615d667c4c3d84166e0def623a041cefc1531cab186141d3ff026e7ec4d97ad3eed9aa64d4
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module Statistics
|
2
2
|
module StatisticalTest
|
3
3
|
class TTest
|
4
|
+
# Errors for Zero std
|
5
|
+
class ZeroStdError < StandardError
|
6
|
+
STD_ERROR_MSG = 'Standard deviation for the difference or group is zero. Please, reconsider sample contents'.freeze
|
7
|
+
end
|
8
|
+
|
4
9
|
# Perform a T-Test for one or two samples.
|
5
10
|
# For the tails param, we need a symbol: :one_tail or :two_tail
|
6
11
|
def self.perform(alpha, tails, *args)
|
@@ -8,9 +13,13 @@ module Statistics
|
|
8
13
|
|
9
14
|
degrees_of_freedom = 0
|
10
15
|
|
16
|
+
# If the comparison mean has been specified
|
11
17
|
t_score = if args[0].is_a? Numeric
|
12
18
|
data_mean = args[1].mean
|
13
19
|
data_std = args[1].standard_deviation
|
20
|
+
|
21
|
+
raise ZeroStdError, ZeroStdError::STD_ERROR_MSG if data_std == 0
|
22
|
+
|
14
23
|
comparison_mean = args[0]
|
15
24
|
degrees_of_freedom = args[1].size
|
16
25
|
|
@@ -43,11 +52,17 @@ module Statistics
|
|
43
52
|
end
|
44
53
|
|
45
54
|
def self.paired_test(alpha, tails, left_group, right_group)
|
55
|
+
raise StandardError, 'both samples are the same' if left_group == right_group
|
56
|
+
|
46
57
|
# Handy snippet grabbed from https://stackoverflow.com/questions/2682411/ruby-sum-corresponding-members-of-two-or-more-arrays
|
47
58
|
differences = [left_group, right_group].transpose.map { |value| value.reduce(:-) }
|
48
59
|
|
49
60
|
degrees_of_freedom = differences.size - 1
|
50
|
-
|
61
|
+
difference_std = differences.standard_deviation
|
62
|
+
|
63
|
+
raise ZeroStdError, ZeroStdError::STD_ERROR_MSG if difference_std == 0
|
64
|
+
|
65
|
+
down = difference_std/Math.sqrt(differences.size)
|
51
66
|
|
52
67
|
t_score = (differences.mean - 0)/down.to_f
|
53
68
|
|
data/lib/statistics/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-statistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- esteban zapata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.7.3
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: A ruby gem for som specific statistics. Inspired by the jStat js library.
|