least_squares 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +49 -0
- data/least_squares.gemspec +23 -0
- data/spec/least_squares_spec.rb +42 -0
- data/spec/spec_helper.rb +5 -0
- metadata +11 -6
data/.gemtest
ADDED
File without changes
|
data/CHANGELOG.md
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
CLOBBER.include('doc', '.yardoc')
|
5
|
+
|
6
|
+
def gemspec
|
7
|
+
@gemspec ||= begin
|
8
|
+
file = File.expand_path("../least_squares.gemspec", __FILE__)
|
9
|
+
eval(File.read(file), binding, file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new
|
16
|
+
rescue LoadError
|
17
|
+
task(:spec){abort "`gem install rspec` to run specs"}
|
18
|
+
end
|
19
|
+
task :default => :spec
|
20
|
+
task :test => :spec
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'yard'
|
24
|
+
YARD::Rake::YardocTask.new do |t|
|
25
|
+
t.options << "--files" << "CHANGELOG.md,LICENSE"
|
26
|
+
end
|
27
|
+
rescue LoadError
|
28
|
+
task(:yardoc){abort "`gem install yard` to generate documentation"}
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rake/gempackagetask'
|
33
|
+
Rake::GemPackageTask.new(gemspec) do |pkg|
|
34
|
+
pkg.gem_spec = gemspec
|
35
|
+
end
|
36
|
+
task :gem => :gemspec
|
37
|
+
rescue LoadError
|
38
|
+
task(:gem){abort "`gem install rake` to package gems"}
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Install the gem locally"
|
42
|
+
task :install => :gem do
|
43
|
+
sh "gem install pkg/#{gemspec.full_name}.gem"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Validate the gemspec"
|
47
|
+
task :gemspec do
|
48
|
+
gemspec.validate
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "least_squares"
|
3
|
+
s.version = "1.0.1"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Shane Emmons"]
|
6
|
+
s.email = "semmons99@gmail.com"
|
7
|
+
s.homepage = "http://github.com/semmons99/least_squares"
|
8
|
+
s.summary = "Calulate the Least Squares Regression Line"
|
9
|
+
s.description = "This gem adds methods to the Math module to aid in calculating the Least Squares Regression Line given two arrays."
|
10
|
+
|
11
|
+
s.required_rubygems_version = ">= 1.3.6"
|
12
|
+
|
13
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
14
|
+
s.add_development_dependency "yard"
|
15
|
+
|
16
|
+
s.files = Dir.glob("lib/**/*")
|
17
|
+
s.files += Dir.glob("spec/**/*")
|
18
|
+
s.files += %w(CHANGELOG.md LICENSE README.md)
|
19
|
+
s.files += %w(Rakefile .gemtest least_squares.gemspec)
|
20
|
+
|
21
|
+
s.require_path = "lib"
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "LeastSquares" do
|
4
|
+
before(:each) do
|
5
|
+
@xs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
6
|
+
@ys = [9, 1, 0, 5, 4, 7, 7, 0, 9, 3]
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#mean' do
|
10
|
+
specify 'returns the mean (average) of an array of numbers' do
|
11
|
+
Math.mean(@xs).should == 5.5
|
12
|
+
Math.mean(@ys).should == 4.5
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#stdev' do
|
17
|
+
specify 'returns the standard deviation of an array of numbers' do
|
18
|
+
Math.stdev(@xs).should be_within(0.0001).of(3.0277)
|
19
|
+
Math.stdev(@ys).should be_within(0.0001).of(3.4721)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#pearson' do
|
24
|
+
specify 'returns the Pearson Correlation Coefficient of two arrays of numbers' do
|
25
|
+
Math.pearson(@xs,@ys).should be_within(0.0001).of(0.0581)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#least_squares' do
|
30
|
+
specify 'returns the Least Squares Regression Line of two arrays of numbers as a Proc' do
|
31
|
+
Math.least_squares(@xs,@ys).should be_a(Proc)
|
32
|
+
end
|
33
|
+
|
34
|
+
specify 'return the Least Squares Regression Line of two arrays of numbers' do
|
35
|
+
rs = [4.2, 4.2667, 4.3333, 4.4, 4.4667, 4.5333, 4.6, 4.6667, 4.7333, 4.8]
|
36
|
+
ls = Math.least_squares(@xs,@ys)
|
37
|
+
(1..10).map{|i| ls.call(i)}.each_with_index do |x,i|
|
38
|
+
x.should be_within(0.0001).of(rs[i])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: least_squares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shane Emmons
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-14 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -58,9 +58,14 @@ extra_rdoc_files: []
|
|
58
58
|
|
59
59
|
files:
|
60
60
|
- lib/least_squares.rb
|
61
|
+
- spec/least_squares_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
61
63
|
- CHANGELOG.md
|
62
64
|
- LICENSE
|
63
65
|
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- .gemtest
|
68
|
+
- least_squares.gemspec
|
64
69
|
has_rdoc: true
|
65
70
|
homepage: http://github.com/semmons99/least_squares
|
66
71
|
licenses: []
|
@@ -93,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
98
|
requirements: []
|
94
99
|
|
95
100
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.5.0
|
97
102
|
signing_key:
|
98
103
|
specification_version: 3
|
99
104
|
summary: Calulate the Least Squares Regression Line
|