correlations 1.0.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/correlations +19 -0
- data/correlations.gemspec +29 -0
- data/data/glucose.csv +7 -0
- data/data/weather.csv +6 -0
- data/lib/correlations.rb +32 -0
- data/lib/correlations/version.rb +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b8dd1e7636624565004a91b5a7efb680dbce344ce8620ceac0c192ef62b2897
|
4
|
+
data.tar.gz: 28b4168c36cf7c7fbd821f68a41a3dc4c190ad3056dc5cc327fdad56eeddb8d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e27d65489f767cb4c984bfe72cf562c90d7602f88c0e6722e995443e1e4bb59724e946ee2612891243ec04d8769edbbb3ff089ebce50e2a6a56cc0140b12c0f4
|
7
|
+
data.tar.gz: 7d2a879e7392a870e3409099222a10c98a762cdeb4b7d188fdd36f7c6bd8f198f2e299abfb090e7b8dea00262436c2b714adf0a88d5e632335f327a779214c28
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
correlations (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
correlations!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Christoffer Artmann
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Correlation
|
2
|
+
|
3
|
+
Correlations is a gem that can be used to calculate Pearson Correlation Coefficients for a data set.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Install the gem
|
8
|
+
|
9
|
+
$ gem install correlations
|
10
|
+
|
11
|
+
|
12
|
+
Calculate the correlation between values
|
13
|
+
|
14
|
+
$ correlations weather.csv
|
15
|
+
|
16
|
+
|
17
|
+
Correlations works on CSV files with headers.
|
18
|
+
|
19
|
+
|Days with Snow|Average Temperature|Average Wind Speed|
|
20
|
+
|--------------|:-----------------:|:----------------:|
|
21
|
+
| 43 | 9.4 | 8.8 |
|
22
|
+
| 25 | 9.5 | 10.5 |
|
23
|
+
| 28 | 9.6 | 10.6 |
|
24
|
+
| 41 | 8.8 | 9.8 |
|
25
|
+
| 74 | 6.6 | 9.2 |
|
26
|
+
|
27
|
+
It will calculate the Pearson correlation coefficient between the values in the first column and each of the other columns.
|
28
|
+
|
29
|
+
$ correlations weather.csv
|
30
|
+
|
31
|
+
Calculating correlations for data set weather.csv
|
32
|
+
|
33
|
+
Average Temperature: -0.9499166137289158
|
34
|
+
Average Wind Speed: -0.7059250219593274
|
35
|
+
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/artmann/correlations.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/correlations
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/correlations'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
if ARGV.length == 0
|
7
|
+
puts "Filename is required"
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
path = Pathname.new(ARGV[0]).realpath.to_s
|
12
|
+
|
13
|
+
puts "Calculating correlations for data set #{path}"
|
14
|
+
correlations = Correlations::Correlations.new.from_csv(path)
|
15
|
+
|
16
|
+
puts ""
|
17
|
+
correlations.keys.each do |key|
|
18
|
+
puts "#{key.gsub('_', ' ').gsub('-', ' ').capitalize}: #{correlations[key]}"
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "correlations/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "correlations"
|
8
|
+
spec.version = Correlations::VERSION
|
9
|
+
spec.authors = ["Christoffer Artmann"]
|
10
|
+
spec.email = ["christoffer@artmann.co"]
|
11
|
+
|
12
|
+
spec.summary = "Calculate Pearson correlation coefficients"
|
13
|
+
spec.description = "Command line gem for calculating Pearson correlation coefficients from data sets"
|
14
|
+
spec.homepage = "https://github.com/artmann/correlations"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "bin"
|
23
|
+
spec.executables = ['correlations']
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
data/data/glucose.csv
ADDED
data/data/weather.csv
ADDED
data/lib/correlations.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require_relative "./correlations/version"
|
3
|
+
|
4
|
+
module Correlations
|
5
|
+
class Correlations
|
6
|
+
def from_csv(path)
|
7
|
+
|
8
|
+
raw = File.read(path)
|
9
|
+
|
10
|
+
data = CSV.parse(raw, headers: true).map(&:to_h)
|
11
|
+
|
12
|
+
sample_size = data.size
|
13
|
+
primary_key = data.first.keys.first
|
14
|
+
correlations = {}
|
15
|
+
|
16
|
+
data.first.keys.reject { |k| k == primary_key }.each do |key|
|
17
|
+
x = data.map { |r| r[primary_key] }.map(&:to_f)
|
18
|
+
y = data.map { |r| r[key] }.map(&:to_f)
|
19
|
+
xx = x.map { |x| x ** 2 }.sum
|
20
|
+
yy = y.map { |y| y ** 2 }.sum
|
21
|
+
xy = x.each_with_index.map { |x, i| x * y[i] }.sum
|
22
|
+
|
23
|
+
a = (sample_size * xy - x.sum * y.sum)
|
24
|
+
b = Math.sqrt((sample_size * xx - x.sum ** 2) * (sample_size * yy - y.sum ** 2))
|
25
|
+
|
26
|
+
correlations[key] = a / b
|
27
|
+
end
|
28
|
+
|
29
|
+
return correlations
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: correlations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christoffer Artmann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Command line gem for calculating Pearson correlation coefficients from
|
56
|
+
data sets
|
57
|
+
email:
|
58
|
+
- christoffer@artmann.co
|
59
|
+
executables:
|
60
|
+
- correlations
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/correlations
|
73
|
+
- correlations.gemspec
|
74
|
+
- data/glucose.csv
|
75
|
+
- data/weather.csv
|
76
|
+
- lib/correlations.rb
|
77
|
+
- lib/correlations/version.rb
|
78
|
+
homepage: https://github.com/artmann/correlations
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.7.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Calculate Pearson correlation coefficients
|
102
|
+
test_files: []
|