byar 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/byar.rb +92 -3
- metadata +17 -26
data/lib/byar.rb
CHANGED
@@ -1,13 +1,102 @@
|
|
1
|
+
##
|
2
|
+
# Byar is a Byar's approximation confidence interval tool with SMR calculation.
|
3
|
+
#
|
4
|
+
# Can be used with class-level methods or as instantiated object.
|
5
|
+
#
|
6
|
+
# Class-level example with observed value 100 and expected value 90:
|
7
|
+
#
|
8
|
+
# Byar.upper(100, 90) # => 1.3514260807978444, equals to SMR of 135.1
|
9
|
+
#
|
10
|
+
# Object instance example with observed value 100 and expected value 90:
|
11
|
+
#
|
12
|
+
# b = Byar.new(100)
|
13
|
+
# b.upper_bound # => 121.628347271806
|
14
|
+
# b.lower(90) # => 0.9040199067337297, equals to SMR of 90.4
|
15
|
+
#
|
1
16
|
class Byar
|
17
|
+
##
|
18
|
+
# Z_VALUE defaults to 1.96 for 95% confidence interval
|
19
|
+
#
|
20
|
+
Z_VALUE = 1.96
|
21
|
+
|
22
|
+
attr_writer :z_value
|
23
|
+
|
24
|
+
##
|
25
|
+
# Create new Byar approximation calculator for +obs+ observed cases
|
26
|
+
def initialize(obs)
|
27
|
+
@obs = obs
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Calculate SMR-like lower boundary (1 equals SMR of 100)
|
32
|
+
#
|
33
|
+
# Give +obs+ observed and +exp+ expected values to return a lower SMR-like
|
34
|
+
# boundary value (0 - Infinite)
|
2
35
|
def self.lower(obs, exp)
|
3
36
|
return nil if exp == 0
|
4
|
-
|
5
|
-
obs.quo(exp) * (1 - 1.quo(9 * obs) - 1.96.quo(3 * Math.sqrt(obs))) ** 3
|
37
|
+
lower_bound(obs).quo(exp)
|
6
38
|
end
|
7
39
|
|
40
|
+
##
|
41
|
+
# Calculate SMR-like upper boundary (1 equals SMR of 100)
|
42
|
+
#
|
43
|
+
# Give +obs+ observed and +exp+ expected values to return an upper SMR-like
|
44
|
+
# boundary value (0 - Infinite)
|
8
45
|
def self.upper(obs, exp)
|
9
46
|
return nil if exp == 0
|
47
|
+
upper_bound(obs).quo(exp)
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Calculate lower boundary for observed cases
|
52
|
+
def self.lower_bound(obs)
|
53
|
+
return 0 if obs == 0
|
54
|
+
obs * (1 - 1.quo(9 * obs) - Z_VALUE.quo(3 * Math.sqrt(obs))) ** 3
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Calculate upper boundary for observed cases
|
59
|
+
def self.upper_bound(obs)
|
10
60
|
obs = obs + 1
|
11
|
-
|
61
|
+
obs * (1 - 1.quo(9 * obs) + Z_VALUE.quo(3 * Math.sqrt(obs))) ** 3
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.z_value=(value)
|
65
|
+
@z_value = value
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.z_value
|
69
|
+
@z_value ||= Z_VALUE
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Give lower SMR-like boundary for +expected+ cases
|
74
|
+
def lower(expected)
|
75
|
+
self.class.lower(@obs, expected)
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Give upper SMR-like boundary for +expected+ cases
|
80
|
+
def upper(expected)
|
81
|
+
self.class.upper(@obs, expected)
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Give lower boundary for observed value
|
86
|
+
def lower_bound
|
87
|
+
self.class.lower_bound(@obs)
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Give upper boundary for observed value
|
92
|
+
def upper_bound
|
93
|
+
self.class.upper_bound(@obs)
|
12
94
|
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Give object's Z value, with fallback to Class variable or Z_VALUE
|
98
|
+
def z_value
|
99
|
+
@z_value ||= self.class.z_value
|
100
|
+
end
|
101
|
+
|
13
102
|
end
|
metadata
CHANGED
@@ -1,54 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: byar
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Floris Huetink
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-09-02 00:00:00 Z
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
14
|
description: Byar's approximation for use in (H)SMR calculations
|
17
15
|
email: floris@avocado.nl
|
18
16
|
executables: []
|
19
|
-
|
20
17
|
extensions: []
|
21
|
-
|
22
18
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
files:
|
19
|
+
files:
|
25
20
|
- lib/byar.rb
|
26
21
|
homepage: https://github.com/florish/byar
|
27
22
|
licenses: []
|
28
|
-
|
29
23
|
post_install_message:
|
30
24
|
rdoc_options: []
|
31
|
-
|
32
|
-
require_paths:
|
25
|
+
require_paths:
|
33
26
|
- lib
|
34
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
28
|
none: false
|
36
|
-
requirements:
|
37
|
-
- -
|
38
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
39
32
|
version: 1.9.2
|
40
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
34
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
46
39
|
requirements: []
|
47
|
-
|
48
40
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
41
|
+
rubygems_version: 1.8.24
|
50
42
|
signing_key:
|
51
43
|
specification_version: 3
|
52
44
|
summary: Byar's approximation
|
53
45
|
test_files: []
|
54
|
-
|