statsample 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'minitest'
4
+ gem 'rdoc'
5
+ gem 'mocha', '0.10.5' #:require=>'mocha/setup'
6
+ gem 'shoulda','2.11.3'
7
+ gem 'shoulda-matchers','1.1.0'
8
+ gem 'hoe'
9
+ gem 'bio-statsample-timeseries'
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.10)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ hoe (3.4.0)
8
+ rake (>= 0.8, < 11.0)
9
+ i18n (0.6.1)
10
+ json (1.7.6)
11
+ metaclass (0.0.1)
12
+ minitest (4.3.3)
13
+ mocha (0.10.5)
14
+ metaclass (~> 0.0.1)
15
+ multi_json (1.5.0)
16
+ rake (10.0.3)
17
+ rdoc (3.12)
18
+ json (~> 1.4)
19
+ shoulda (2.11.3)
20
+ shoulda-matchers (1.1.0)
21
+ activesupport (>= 3.0.0)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ hoe
28
+ minitest
29
+ mocha (= 0.10.5)
30
+ rdoc
31
+ shoulda (= 2.11.3)
32
+ shoulda-matchers (= 1.1.0)
@@ -1,3 +1,13 @@
1
+ === 1.3.0 / 2013-09-19
2
+
3
+ * Merge remote-tracking branch 'vpereira/master' into vpereira
4
+ * New Wilcoxon Signed Rank test
5
+ * Remove TimeSeries class. Now is available on gem "bio-statsample-timeseries" [GSOC 2013 project :) ]
6
+ * Update shoulda support
7
+ * added Bundle depds
8
+ * improved the csv read method (requires tests)
9
+ * open svg on mac osx
10
+
1
11
  === 1.2.0 / 2011-12-15
2
12
 
3
13
  * Added support for time series (TimeSeries object): MA, EMA, MACD, acf, lag and delta. [Rob Britton]
@@ -1,3 +1,5 @@
1
+ Gemfile
2
+ Gemfile.lock
1
3
  History.txt
2
4
  LICENSE.txt
3
5
  Manifest.txt
@@ -102,7 +104,7 @@ lib/statsample/test/kolmogorovsmirnov.rb
102
104
  lib/statsample/test/levene.rb
103
105
  lib/statsample/test/t.rb
104
106
  lib/statsample/test/umannwhitney.rb
105
- lib/statsample/timeseries.rb
107
+ lib/statsample/test/wilcoxonsignedrank.rb
106
108
  lib/statsample/vector.rb
107
109
  lib/statsample/vector/gsl.rb
108
110
  po/es/statsample.mo
@@ -161,5 +163,6 @@ test/test_test_t.rb
161
163
  test/test_tseries.rb
162
164
  test/test_umannwhitney.rb
163
165
  test/test_vector.rb
166
+ test/test_wilcoxonsignedrank.rb
164
167
  test/test_xls.rb
165
168
  web/Rakefile
data/Rakefile CHANGED
@@ -43,11 +43,11 @@ end
43
43
  h=Hoe.spec('statsample') do
44
44
  self.version=Statsample::VERSION
45
45
  #self.testlib=:minitest
46
- self.rubyforge_name = "ruby-statsample"
47
- self.developer('Claudio Bustos', 'clbustos@gmail.com')
48
- self.extra_deps << ["spreadsheet","~>0.6.5"] << ["reportbuilder", "~>1.4"] << ["minimization", "~>0.2.0"] << ["fastercsv", ">0"] << ["dirty-memoize", "~>0.0"] << ["extendmatrix","~>0.3.1"] << ["statsample-bivariate-extension", ">0"] << ["rserve-client", "~>0.2.5"] << ["rubyvis", "~>0.5"] << ["distribution", "~>0.6"]
46
+ self.rubyforge_name = "ruby-statsample"
47
+ self.developer('Claudio Bustos', 'clbustos@gmail.com')
48
+ self.extra_deps << ["spreadsheet","~>0.6.5"] << ["reportbuilder", "~>1.4"] << ["minimization", "~>0.2.0"] << ["fastercsv", ">0"] << ["dirty-memoize", "~>0.0"] << ["extendmatrix","~>0.3.1"] << ["statsample-bivariate-extension", ">0"] << ["rserve-client", "~>0.2.5"] << ["rubyvis", "~>0.5"] << ["distribution", "~>0.6"]
49
49
 
50
- self.extra_dev_deps << ["hoe","~>0"] << ["shoulda","~>0"] << ["minitest", "~>2.0"] << ["rserve-client", "~>0"] << ["gettext", "~>0"] << ["mocha", "~>0"] << ["hoe-git", "~>0"]
50
+ self.extra_dev_deps << ["hoe","~>0"] << ["shoulda","~>3.1.1"] << ["minitest", "~>2.0"] << ["rserve-client", "~>0"] << ["gettext", "~>0"] << ["mocha", "~>0"] << ["hoe-git", "~>0"]
51
51
 
52
52
  self.clean_globs << "test/images/*" << "demo/item_analysis/*" << "demo/Regression"
53
53
  self.post_install_message = <<-EOF
@@ -69,7 +69,7 @@ source code first.
69
69
 
70
70
  *****************************************************
71
71
  EOF
72
- self.need_rdoc=false
72
+ self.need_rdoc=false
73
73
  end
74
74
 
75
75
  if Rake.const_defined?(:RDocTask)
@@ -26,7 +26,6 @@ require 'dirty-memoize'
26
26
  require 'reportbuilder'
27
27
 
28
28
 
29
-
30
29
  class Numeric
31
30
  def square ; self * self ; end
32
31
  end
@@ -134,7 +133,7 @@ module Statsample
134
133
 
135
134
  create_has_library :gsl
136
135
 
137
- VERSION = '1.2.0'
136
+ VERSION = '1.3.0'
138
137
  SPLIT_TOKEN = ","
139
138
  autoload(:Analysis, 'statsample/analysis')
140
139
  autoload(:Database, 'statsample/converters')
@@ -161,7 +160,6 @@ module Statsample
161
160
  autoload(:Test, 'statsample/test')
162
161
  autoload(:Factor, 'statsample/factor')
163
162
  autoload(:Graph, 'statsample/graph')
164
- autoload(:TimeSeries, 'statsample/timeseries')
165
163
 
166
164
 
167
165
  class << self
@@ -62,7 +62,11 @@ module Statsample
62
62
  require 'tmpdir'
63
63
  fn=Dir.tmpdir+"/image_#{Time.now.to_f}.svg"
64
64
  File.open(fn,"w") {|fp| fp.write svg}
65
- `xdg-open '#{fn}'`
65
+ if RUBY_PLATFORM =~/darwin/
66
+ %x(open -a safari #{fn})
67
+ else
68
+ %x(xdg-open #{fn})
69
+ end
66
70
  end
67
71
  def boxplot(*args)
68
72
  show_svg(old_boxplot(*args).to_svg)
@@ -8,6 +8,25 @@ module Statsample
8
8
  CSV_klass=::CSV
9
9
  end
10
10
  class << self
11
+
12
+ def read19(filename,ignore_lines=0,csv_opts=Hash.new)
13
+ #default first line is header
14
+ csv_opts.merge!(:headers=>true, :header_converters => :symbol)
15
+ csv = CSV_klass::Table.new(CSV_klass::read(filename,'r',csv_opts))
16
+ csv_headers = if csv_opts[:headers]
17
+ csv.headers
18
+ else
19
+ #as in R, if no header we name the headers as V1,V2,V3,V4,..
20
+ 1.upto(csv.first.length).collect { |i| "V#{i}" }
21
+ end
22
+ #we invert row -> column. It means csv[0] is the first column and not row. Similar to R
23
+ csv.by_col!
24
+ thash = {}
25
+ csv_headers.each_with_index do |header,idx|
26
+ thash[header] = Statsample::Vector.new(csv[idx].drop(ignore_lines))
27
+ end
28
+ ds=Statsample::Dataset.new(thash)
29
+ end
11
30
  # Returns a Dataset based on a csv file
12
31
  #
13
32
  # USE:
@@ -705,7 +705,7 @@ module Statsample
705
705
 
706
706
  # Return a correlation matrix for fields included as parameters.
707
707
  # By default, uses all fields of dataset
708
- def correlation_matrix(fields=nil)
708
+ def correlation_matrix(fields=nil)
709
709
  if fields
710
710
  ds=clone(fields)
711
711
  else
@@ -715,7 +715,7 @@ module Statsample
715
715
  end
716
716
  # Return a correlation matrix for fields included as parameters.
717
717
  # By default, uses all fields of dataset
718
- def covariance_matrix(fields=nil)
718
+ def covariance_matrix(fields=nil)
719
719
  if fields
720
720
  ds=clone(fields)
721
721
  else
@@ -9,6 +9,8 @@ module Statsample
9
9
  autoload(:ChiSquare, 'statsample/test/chisquare')
10
10
  autoload(:BartlettSphericity, 'statsample/test/bartlettsphericity')
11
11
  autoload(:KolmogorovSmirnov, 'statsample/test/kolmogorovsmirnov')
12
+ autoload(:WilcoxonSignedRank, 'statsample/test/wilcoxonsignedrank')
13
+
12
14
 
13
15
  # Returns probability of getting a value lower or higher
14
16
  # than sample, using cdf and number of tails.
@@ -66,7 +68,10 @@ module Statsample
66
68
  def t_two_samples_independent(v1,v2, opts=Hash.new)
67
69
  Statsample::Test::T::TwoSamplesIndependent.new(v1,v2,opts)
68
70
  end
69
-
71
+ # Shorthand for Statsample::Test::WilcoxonSignedRank.new
72
+ def wilcoxon_signed_rank(v1,v2,opts=Hash.new)
73
+ Statsample::Test::WilcoxonSignedRank.new(v1,v2,opts)
74
+ end
70
75
  # Shorthand for Statsample::Test::Levene.new
71
76
  def levene(input, opts=Hash.new)
72
77
  Statsample::Test::Levene.new(input,opts)
@@ -0,0 +1,88 @@
1
+ module Statsample
2
+ module Test
3
+ # From Wikipedia:
4
+ # The Wilcoxon signed-rank test is a non-parametric statistical hypothesis test used when comparing two related samples, matched samples, or repeated measurements on a single sample to assess whether their population mean ranks differ (i.e. it is a paired difference test). It can be used as an alternative to the paired Student's t-test, t-test for matched pairs, or the t-test for dependent samples when the population cannot be assumed to be normally distributed.
5
+ class WilcoxonSignedRank
6
+ include Statsample::Test
7
+ include Summarizable
8
+
9
+ # Name of F analysis
10
+ attr_accessor :name
11
+ attr_reader :w
12
+ attr_reader :nr
13
+ attr_writer :tails
14
+ # Parameters:
15
+ def initialize(v1,v2, opts=Hash.new)
16
+ @v1=v1
17
+ @v2=v2
18
+ opts_default={:name=>_("Wilcoxon Signed Rank Test"),:tails=>:both}
19
+ @opts=opts_default.merge(opts)
20
+ opts_default.keys.each {|k|
21
+ send("#{k}=", @opts[k])
22
+ }
23
+ calculate
24
+ end
25
+ def calculate
26
+ df=Statsample::Dataset.new({'v1'=>@v1,'v2'=>@v2})
27
+ df["abs"]=df.collect {|row|
28
+ r=(row["v2"]-row["v1"]).abs
29
+ }
30
+ df["sgn"]=df.collect {|row|
31
+ r=row["v2"]-row["v1"]
32
+ r==0 ? 0 : r/r.abs
33
+ }
34
+ df=df.filter {|row| row["sgn"]!=0}
35
+ df["rank"]=df["abs"].ranked
36
+ @nr=df.cases
37
+ @w=df.collect {|row|
38
+ row["sgn"]*row["rank"]
39
+ #p row["sgn"]*row["rank"]
40
+ }.sum
41
+ end
42
+ def report_building(generator) # :nodoc:
43
+ generator.section(:name=>@name) do |s|
44
+ s.table(:name=>_("%s results") % @name) do |t|
45
+ t.row([_("W Value"), "%0.3f" % @w])
46
+ t.row([_("Z"), "%0.3f (p: %0.3f)" % [z, probability_z]])
47
+ if(nr<=10)
48
+ t.row([_("Exact probability"), "p-exact: %0.3f" % [probability_exact]])
49
+ end
50
+ end
51
+ end
52
+ end
53
+ def z
54
+ sigma=Math.sqrt((nr*(nr+1)*(2*nr+1))/6)
55
+ (w-0.5)/sigma
56
+ end
57
+ # Assuming normal distribution of W, this calculate
58
+ # the probability of samples with Z equal or higher than
59
+ # obtained on sample
60
+ def probability_z
61
+ (1-Distribution::Normal.cdf(z))*(@tails==:both ? 2:1)
62
+ end
63
+ # Calculate exact probability.
64
+ # Don't calculate for large Nr, please!
65
+ def probability_exact
66
+ str_format="%0#{nr}b"
67
+ combinations=2**nr
68
+ #p str_format
69
+ total_w=combinations.times.map {|i|
70
+ comb=sprintf(str_format,i)
71
+ w_local=comb.length.times.inject(0) {|ac,j|
72
+ sgn=comb[j]=="0" ? -1 : 1
73
+ ac+(j+1)*sgn
74
+ }
75
+ }.sort
76
+ total_w.find_all {|v|
77
+ if @tails==:both
78
+ v<=-w.abs or v>=w.abs
79
+ elsif @tails==:left
80
+ v<=w
81
+ elsif @tails==:right
82
+ v>=w
83
+ end
84
+ }.count/(combinations.to_f)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -2,10 +2,11 @@ $:.unshift(File.expand_path(File.dirname(__FILE__)+'/../lib/'))
2
2
  $:.unshift(File.expand_path(File.dirname(__FILE__)+'/'))
3
3
 
4
4
  require 'minitest/unit'
5
- require 'mocha'
5
+ require 'mocha/setup'
6
6
  require 'tempfile'
7
7
  require 'tmpdir'
8
8
  require 'shoulda'
9
+ require 'shoulda-context'
9
10
  require 'fixtures/correlation_matrix'
10
11
 
11
12
  require 'statsample'
@@ -14,10 +15,9 @@ require 'statsample'
14
15
  module MiniTest
15
16
  class Unit
16
17
  class TestCase
17
- include Shoulda::InstanceMethods
18
- extend Shoulda::ClassMethods
19
- include Shoulda::Assertions
20
-
18
+ include Shoulda::Context::Assertions
19
+ include Shoulda::Context::InstanceMethods
20
+ extend Shoulda::Context::ClassMethods
21
21
  def self.should_with_gsl(name,&block)
22
22
  should(name) do
23
23
  if Statsample.has_gsl?
@@ -38,3 +38,43 @@ class StatsampleCSVTestCase < MiniTest::Unit::TestCase
38
38
  }
39
39
  end
40
40
  end
41
+
42
+ class StatsampleCSVTestCase2 < MiniTest::Unit::TestCase
43
+ def setup
44
+ @ds=Statsample::CSV.read19(File.dirname(__FILE__)+"/fixtures/test_csv.csv")
45
+ end
46
+ def test_read
47
+ assert_equal(6,@ds.cases)
48
+ assert_equal(%w{id name age city a1}, @ds.fields)
49
+ id=[1,2,3,4,5,6].to_vector(:scale)
50
+ name=["Alex","Claude","Peter","Franz","George","Fernand"].to_vector(:nominal)
51
+ age=[20,23,25,27,5.5,nil].to_vector(:scale)
52
+ city=["New York","London","London","Paris","Tome",nil].to_vector(:nominal)
53
+ a1=["a,b","b,c","a",nil,"a,b,c",nil].to_vector(:nominal)
54
+ ds_exp=Statsample::Dataset.new({'id'=>id,'name'=>name,'age'=>age,'city'=>city,'a1'=>a1}, %w{id name age city a1})
55
+ ds_exp.fields.each{|f|
56
+ assert_equal(ds_exp[f],@ds[f])
57
+ }
58
+ assert_equal(ds_exp,@ds)
59
+ end
60
+ def test_nil
61
+ assert_equal(nil,@ds['age'][5])
62
+ end
63
+ def test_repeated
64
+ ds=Statsample::CSV.read19(File.dirname(__FILE__)+"/fixtures/repeated_fields.csv")
65
+ assert_equal(%w{id name_1 age_1 city a1 name_2 age_2},ds.fields)
66
+ age=[3,4,5,6,nil,8].to_vector(:scale)
67
+ assert_equal(age,ds['age_2'])
68
+ end
69
+ def test_write
70
+ filename=Tempfile.new("afile")
71
+ # filename=Dir::tmpdir+"/test_write.csv"
72
+ Statsample::CSV.write(@ds, filename.path)
73
+ ds2=Statsample::CSV.read19(filename.path)
74
+ i=0
75
+ ds2.each_array{|row|
76
+ assert_equal(@ds.case_as_array(i),row)
77
+ i+=1
78
+ }
79
+ end
80
+ end
@@ -0,0 +1,67 @@
1
+ require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
2
+
3
+ class StatsampleUMannWhitneyTestCase < MiniTest::Unit::TestCase
4
+ include Statsample::Test
5
+ context Statsample::Test::WilcoxonSignedRank do
6
+ context "Example 1" do
7
+ setup do
8
+ @v1=[110,122,125,120,140,124,123,137,135,145].to_scale
9
+ @v2=[125,115,130,140,140,115,140,125,140,135].to_scale
10
+ @u=Statsample::Test::WilcoxonSignedRank.new(@v1,@v2)
11
+ end
12
+ should "have same result using class or Test#u_mannwhitney" do
13
+ assert_equal(Statsample::Test.wilcoxon_signed_rank(@v1,@v2).w, @u.w)
14
+ end
15
+ should "have correct W values" do
16
+ assert_equal(9,@u.w)
17
+ end
18
+ should "have correct nr values" do
19
+ assert_equal(9,@u.nr)
20
+ end
21
+ should "have correct value for z" do
22
+ assert_in_delta(0.503,@u.z,0.001)
23
+ end
24
+ should "have correct value for probability_z" do
25
+ assert_in_delta(0.614,@u.probability_z,0.001)
26
+ end
27
+ should "have correct value for probability_exact" do
28
+ assert_in_delta(0.652,@u.probability_exact,0.001)
29
+ end
30
+ should "have summary" do
31
+ assert(@u.summary!="")
32
+ end
33
+ end
34
+
35
+ context "Example 2" do
36
+ setup do
37
+ @v2=[78,24,64,45,64,52,30,50,64,50,78,22,84,40,90,72].to_scale
38
+ @v1=[78,24,62,48,68,56,25,44,56,40,68,36,68,20,58,32].to_scale
39
+ @u=Statsample::Test::WilcoxonSignedRank.new(@v1,@v2)
40
+ end
41
+ should "have same result using class or Test#u_mannwhitney" do
42
+ assert_equal(Statsample::Test.wilcoxon_signed_rank(@v1,@v2).w, @u.w)
43
+ end
44
+ should "have correct W values" do
45
+ assert_equal(67,@u.w)
46
+ end
47
+ should "have correct nr values" do
48
+ assert_equal(14,@u.nr)
49
+ end
50
+ should "have correct value for z" do
51
+ assert_in_delta(2.087,@u.z,0.001)
52
+ end
53
+ should "have correct value for probability_z" do
54
+ assert_in_delta(0.036,@u.probability_z,0.001)
55
+ end
56
+ should "have correct value for probability_exact" do
57
+ assert_in_delta(0.036,@u.probability_exact,0.001)
58
+ end
59
+ should "have summary" do
60
+ assert(@u.summary!="")
61
+ end
62
+ end
63
+
64
+
65
+ end
66
+
67
+ end
metadata CHANGED
@@ -1,46 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Claudio Bustos
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- - !binary |-
13
- LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURNakNDQWhxZ0F3SUJB
14
- Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREEvTVJFd0R3WURWUVFEREFoamJH
15
- SjEKYzNSdmN6RVZNQk1HQ2dtU0pvbVQ4aXhrQVJrV0JXZHRZV2xzTVJNd0VR
16
- WUtDWkltaVpQeUxHUUJHUllEWTI5dApNQjRYRFRFd01ETXlPVEl4TXpnMU5W
17
- b1hEVEV4TURNeU9USXhNemcxTlZvd1B6RVJNQThHQTFVRUF3d0lZMnhpCmRY
18
- TjBiM014RlRBVEJnb0praWFKay9Jc1pBRVpGZ1ZuYldGcGJERVRNQkVHQ2dt
19
- U0pvbVQ4aXhrQVJrV0EyTnYKYlRDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFB
20
- RGdnRVBBRENDQVFvQ2dnRUJBTGY4SlZNR3FFN201a1liK1BOTgpuZVp2MnBj
21
- WFY1ZlFDaTZ4a3lHOGJpMi9TSUZ5L0x5eHV2THpFZU94QmVhejFCZTkzYmF5
22
- SVVxdU9JcXczZHl3Ci9LWFdhMzFGeHVOdXZBbTZDTjhmeWVSWVgvb3U0Y3cz
23
- T0lVVW5JdkI3Uk1OSXU0d2JnZU02aHRWL1FFc05McnYKYXQxL21oOUpwcWF3
24
- UHJjaklPVk1qNEJJcDY3dm16SkNhVWYrUy9IMnVZdFNPMDlGK1lRRTN0djg1
25
- VFBlUm1xVQp5anlYeVRjL29KaXcxY1hza1VMOFV0TVdabXJ3TkxIWHVaV1dJ
26
- TXpraml6M1VOZGhKci90NVJPazhTMldQem5sCjBiTXkvUE1JbEFicVdvbFJu
27
- MXpsMlZGSjNUYVhTY2JxSW1ZOFdmNGc2MmIvMVpTVWxHcnRuTE5zQ1lYcldp
28
- c28KVVBVQ0F3RUFBYU01TURjd0NRWURWUjBUQkFJd0FEQUxCZ05WSFE4RUJB
29
- TUNCTEF3SFFZRFZSME9CQllFRkd1OQpyckoxSDY0cVJtTk51M0pqL1Fqdmgw
30
- dTVNQTBHQ1NxR1NJYjNEUUVCQlFVQUE0SUJBUUNWMFVua2E1aXNyaFprCkdq
31
- cVNEcVkvNmhGK0cycGJGY2JXVXBqbUM4Tld0QXhlQys3TkdWM2xqZDBlMVNM
32
- Zm95Qmo0Z25GdEZtWThxWDQKSzAydGdTWk0wZURWOFRwZ0ZwV1h6SzZMekh2
33
- b2FudWFoSExaRXRrLytaODg1bEZlbmUrbkhhZGtlbTFuOWlBQgpjczk2Sk85
34
- L0pmRnl1WE0yN3dGQXdtZkhDbUpmUEYwOVI0VnZHSFJBdmI4TUd6U1ZnazJp
35
- MDZPSlRxa0JUd3Z2CkpISmRveXczKzhidzlSSitqTGFOb1EreHUrMXBRZFMy
36
- YmIzbTd4alpwdWZtbC9tOHpGQ3RqWU0vN3Fna0tSOHoKL1padDhsQ2lLZkZB
37
- cnBwUnJaYXlFMkZWc3BzNFg2V3dCZHJLVE1aMENLU1hUUmN0YkVqMUJBWjY3
38
- ZW9UdkJCdApycFAwampzMAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
- date: 2011-12-15 00:00:00.000000000 Z
11
+ cert_chain: []
12
+ date: 2013-09-20 00:00:00.000000000 Z
40
13
  dependencies:
41
14
  - !ruby/object:Gem::Dependency
42
15
  name: spreadsheet
43
- requirement: &16328900 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
44
17
  none: false
45
18
  requirements:
46
19
  - - ~>
@@ -48,10 +21,15 @@ dependencies:
48
21
  version: 0.6.5
49
22
  type: :runtime
50
23
  prerelease: false
51
- version_requirements: *16328900
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.6.5
52
30
  - !ruby/object:Gem::Dependency
53
31
  name: reportbuilder
54
- requirement: &16340700 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
55
33
  none: false
56
34
  requirements:
57
35
  - - ~>
@@ -59,10 +37,15 @@ dependencies:
59
37
  version: '1.4'
60
38
  type: :runtime
61
39
  prerelease: false
62
- version_requirements: *16340700
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.4'
63
46
  - !ruby/object:Gem::Dependency
64
47
  name: minimization
65
- requirement: &16366980 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
66
49
  none: false
67
50
  requirements:
68
51
  - - ~>
@@ -70,10 +53,15 @@ dependencies:
70
53
  version: 0.2.0
71
54
  type: :runtime
72
55
  prerelease: false
73
- version_requirements: *16366980
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
74
62
  - !ruby/object:Gem::Dependency
75
63
  name: fastercsv
76
- requirement: &16365020 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
77
65
  none: false
78
66
  requirements:
79
67
  - - ! '>'
@@ -81,10 +69,15 @@ dependencies:
81
69
  version: '0'
82
70
  type: :runtime
83
71
  prerelease: false
84
- version_requirements: *16365020
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>'
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
85
78
  - !ruby/object:Gem::Dependency
86
79
  name: dirty-memoize
87
- requirement: &16362640 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
88
81
  none: false
89
82
  requirements:
90
83
  - - ~>
@@ -92,10 +85,15 @@ dependencies:
92
85
  version: '0.0'
93
86
  type: :runtime
94
87
  prerelease: false
95
- version_requirements: *16362640
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.0'
96
94
  - !ruby/object:Gem::Dependency
97
95
  name: extendmatrix
98
- requirement: &16360700 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
99
97
  none: false
100
98
  requirements:
101
99
  - - ~>
@@ -103,10 +101,15 @@ dependencies:
103
101
  version: 0.3.1
104
102
  type: :runtime
105
103
  prerelease: false
106
- version_requirements: *16360700
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.3.1
107
110
  - !ruby/object:Gem::Dependency
108
111
  name: statsample-bivariate-extension
109
- requirement: &16385380 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
110
113
  none: false
111
114
  requirements:
112
115
  - - ! '>'
@@ -114,10 +117,15 @@ dependencies:
114
117
  version: '0'
115
118
  type: :runtime
116
119
  prerelease: false
117
- version_requirements: *16385380
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>'
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
118
126
  - !ruby/object:Gem::Dependency
119
127
  name: rserve-client
120
- requirement: &16383940 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
121
129
  none: false
122
130
  requirements:
123
131
  - - ~>
@@ -125,10 +133,15 @@ dependencies:
125
133
  version: 0.2.5
126
134
  type: :runtime
127
135
  prerelease: false
128
- version_requirements: *16383940
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.2.5
129
142
  - !ruby/object:Gem::Dependency
130
143
  name: rubyvis
131
- requirement: &16381840 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
132
145
  none: false
133
146
  requirements:
134
147
  - - ~>
@@ -136,10 +149,15 @@ dependencies:
136
149
  version: '0.5'
137
150
  type: :runtime
138
151
  prerelease: false
139
- version_requirements: *16381840
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.5'
140
158
  - !ruby/object:Gem::Dependency
141
159
  name: distribution
142
- requirement: &16379020 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
143
161
  none: false
144
162
  requirements:
145
163
  - - ~>
@@ -147,10 +165,31 @@ dependencies:
147
165
  version: '0.6'
148
166
  type: :runtime
149
167
  prerelease: false
150
- version_requirements: *16379020
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '0.6'
174
+ - !ruby/object:Gem::Dependency
175
+ name: rdoc
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: '4.0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: '4.0'
151
190
  - !ruby/object:Gem::Dependency
152
191
  name: hoe
153
- requirement: &16402020 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
154
193
  none: false
155
194
  requirements:
156
195
  - - ~>
@@ -158,21 +197,31 @@ dependencies:
158
197
  version: '0'
159
198
  type: :development
160
199
  prerelease: false
161
- version_requirements: *16402020
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ~>
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
162
206
  - !ruby/object:Gem::Dependency
163
207
  name: shoulda
164
- requirement: &16418560 !ruby/object:Gem::Requirement
208
+ requirement: !ruby/object:Gem::Requirement
165
209
  none: false
166
210
  requirements:
167
211
  - - ~>
168
212
  - !ruby/object:Gem::Version
169
- version: '0'
213
+ version: 3.1.1
170
214
  type: :development
171
215
  prerelease: false
172
- version_requirements: *16418560
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ~>
220
+ - !ruby/object:Gem::Version
221
+ version: 3.1.1
173
222
  - !ruby/object:Gem::Dependency
174
223
  name: minitest
175
- requirement: &16432600 !ruby/object:Gem::Requirement
224
+ requirement: !ruby/object:Gem::Requirement
176
225
  none: false
177
226
  requirements:
178
227
  - - ~>
@@ -180,21 +229,15 @@ dependencies:
180
229
  version: '2.0'
181
230
  type: :development
182
231
  prerelease: false
183
- version_requirements: *16432600
184
- - !ruby/object:Gem::Dependency
185
- name: rserve-client
186
- requirement: &16443500 !ruby/object:Gem::Requirement
232
+ version_requirements: !ruby/object:Gem::Requirement
187
233
  none: false
188
234
  requirements:
189
235
  - - ~>
190
236
  - !ruby/object:Gem::Version
191
- version: '0'
192
- type: :development
193
- prerelease: false
194
- version_requirements: *16443500
237
+ version: '2.0'
195
238
  - !ruby/object:Gem::Dependency
196
239
  name: gettext
197
- requirement: &16438020 !ruby/object:Gem::Requirement
240
+ requirement: !ruby/object:Gem::Requirement
198
241
  none: false
199
242
  requirements:
200
243
  - - ~>
@@ -202,10 +245,15 @@ dependencies:
202
245
  version: '0'
203
246
  type: :development
204
247
  prerelease: false
205
- version_requirements: *16438020
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ~>
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
206
254
  - !ruby/object:Gem::Dependency
207
255
  name: mocha
208
- requirement: &16469980 !ruby/object:Gem::Requirement
256
+ requirement: !ruby/object:Gem::Requirement
209
257
  none: false
210
258
  requirements:
211
259
  - - ~>
@@ -213,10 +261,15 @@ dependencies:
213
261
  version: '0'
214
262
  type: :development
215
263
  prerelease: false
216
- version_requirements: *16469980
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ~>
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
217
270
  - !ruby/object:Gem::Dependency
218
271
  name: hoe-git
219
- requirement: &16468800 !ruby/object:Gem::Requirement
272
+ requirement: !ruby/object:Gem::Requirement
220
273
  none: false
221
274
  requirements:
222
275
  - - ~>
@@ -224,18 +277,12 @@ dependencies:
224
277
  version: '0'
225
278
  type: :development
226
279
  prerelease: false
227
- version_requirements: *16468800
228
- - !ruby/object:Gem::Dependency
229
- name: hoe
230
- requirement: &16466880 !ruby/object:Gem::Requirement
280
+ version_requirements: !ruby/object:Gem::Requirement
231
281
  none: false
232
282
  requirements:
233
283
  - - ~>
234
284
  - !ruby/object:Gem::Version
235
- version: '2.12'
236
- type: :development
237
- prerelease: false
238
- version_requirements: *16466880
285
+ version: '0'
239
286
  description: ! 'A suite for basic and advanced statistics on Ruby. Tested on Ruby
240
287
  1.8.7, 1.9.1, 1.9.2 (April, 2010), ruby-head(June, 2011) and JRuby 1.4 (Ruby 1.8.7
241
288
  compatible).
@@ -291,6 +338,8 @@ extra_rdoc_files:
291
338
  - README.txt
292
339
  - references.txt
293
340
  files:
341
+ - Gemfile
342
+ - Gemfile.lock
294
343
  - History.txt
295
344
  - LICENSE.txt
296
345
  - Manifest.txt
@@ -395,7 +444,7 @@ files:
395
444
  - lib/statsample/test/levene.rb
396
445
  - lib/statsample/test/t.rb
397
446
  - lib/statsample/test/umannwhitney.rb
398
- - lib/statsample/timeseries.rb
447
+ - lib/statsample/test/wilcoxonsignedrank.rb
399
448
  - lib/statsample/vector.rb
400
449
  - lib/statsample/vector/gsl.rb
401
450
  - po/es/statsample.mo
@@ -454,11 +503,13 @@ files:
454
503
  - test/test_tseries.rb
455
504
  - test/test_umannwhitney.rb
456
505
  - test/test_vector.rb
506
+ - test/test_wilcoxonsignedrank.rb
457
507
  - test/test_xls.rb
458
508
  - web/Rakefile
459
509
  - .gemtest
460
510
  homepage: http://ruby-statsample.rubyforge.org/
461
- licenses: []
511
+ licenses:
512
+ - MIT
462
513
  post_install_message: ! "***************************************************\nThanks
463
514
  for installing statsample.\n\nOn *nix, you could install statsample-optimization\nto
464
515
  retrieve gems gsl, statistics2 and a C extension\nto speed some methods.\n\n $
@@ -484,48 +535,49 @@ required_rubygems_version: !ruby/object:Gem::Requirement
484
535
  version: '0'
485
536
  requirements: []
486
537
  rubyforge_project: ruby-statsample
487
- rubygems_version: 1.8.10
538
+ rubygems_version: 1.8.25
488
539
  signing_key:
489
540
  specification_version: 3
490
541
  summary: A suite for basic and advanced statistics on Ruby
491
542
  test_files:
543
+ - test/test_regression.rb
544
+ - test/test_reliability_skillscale.rb
545
+ - test/test_anovatwoway.rb
546
+ - test/test_anova_contrast.rb
547
+ - test/test_resample.rb
548
+ - test/test_ggobi.rb
549
+ - test/test_reliability_icc.rb
550
+ - test/test_logit.rb
551
+ - test/test_stratified.rb
552
+ - test/test_srs.rb
553
+ - test/test_test_f.rb
554
+ - test/test_anovawithvectors.rb
555
+ - test/test_reliability.rb
556
+ - test/test_csv.rb
557
+ - test/test_codification.rb
558
+ - test/test_multiset.rb
559
+ - test/test_anovatwowaywithdataset.rb
560
+ - test/test_statistics.rb
492
561
  - test/test_bivariate.rb
562
+ - test/test_histogram.rb
493
563
  - test/test_factor_pa.rb
494
- - test/test_dominance_analysis.rb
564
+ - test/test_analysis.rb
565
+ - test/test_factor_map.rb
566
+ - test/test_anovaoneway.rb
495
567
  - test/test_factor.rb
496
- - test/test_test_kolmogorovsmirnov.rb
497
- - test/test_codification.rb
498
- - test/test_anovatwowaywithdataset.rb
568
+ - test/test_vector.rb
569
+ - test/test_tseries.rb
570
+ - test/test_test_t.rb
571
+ - test/test_dataset.rb
572
+ - test/test_dominance_analysis.rb
573
+ - test/test_gsl.rb
499
574
  - test/test_umannwhitney.rb
500
- - test/test_anova_contrast.rb
501
- - test/test_factor_map.rb
502
- - test/test_anovawithvectors.rb
575
+ - test/test_stest.rb
503
576
  - test/test_crosstab.rb
504
- - test/test_rserve_extension.rb
505
- - test/test_csv.rb
506
- - test/test_analysis.rb
507
577
  - test/test_matrix.rb
508
- - test/test_gsl.rb
509
- - test/test_tseries.rb
510
578
  - test/test_bartlettsphericity.rb
511
- - test/test_mle.rb
512
- - test/test_resample.rb
513
- - test/test_stratified.rb
514
- - test/test_vector.rb
515
- - test/test_srs.rb
516
- - test/test_ggobi.rb
579
+ - test/test_wilcoxonsignedrank.rb
517
580
  - test/test_xls.rb
518
- - test/test_logit.rb
519
- - test/test_stest.rb
520
- - test/test_statistics.rb
521
- - test/test_reliability.rb
522
- - test/test_reliability_icc.rb
523
- - test/test_anovatwoway.rb
524
- - test/test_test_f.rb
525
- - test/test_test_t.rb
526
- - test/test_histogram.rb
527
- - test/test_dataset.rb
528
- - test/test_regression.rb
529
- - test/test_multiset.rb
530
- - test/test_reliability_skillscale.rb
531
- - test/test_anovaoneway.rb
581
+ - test/test_mle.rb
582
+ - test/test_rserve_extension.rb
583
+ - test/test_test_kolmogorovsmirnov.rb
data.tar.gz.sig DELETED
Binary file
@@ -1,169 +0,0 @@
1
- module Statsample::TimeSeriesShorthands
2
- # Creates a new Statsample::TimeSeries object
3
- # Argument should be equal to TimeSeries.new
4
- def to_time_series(*args)
5
- Statsample::TimeSeries::TimeSeries.new(self, :scale, *args)
6
- end
7
-
8
- alias :to_ts :to_time_series
9
- end
10
-
11
- class Array
12
- include Statsample::TimeSeriesShorthands
13
- end
14
-
15
- module Statsample
16
- module TimeSeries
17
- # Collection of data indexed by time.
18
- # The order goes from earliest to latest.
19
- class TimeSeries < Statsample::Vector
20
- # Calculates the autocorrelation coefficients of the series.
21
- #
22
- # The first element is always 1, since that is the correlation
23
- # of the series with itself.
24
- #
25
- # Usage:
26
- #
27
- # ts = (1..100).map { rand }.to_time_series
28
- #
29
- # ts.acf # => array with first 21 autocorrelations
30
- # ts.acf 3 # => array with first 3 autocorrelations
31
- #
32
- def acf maxlags = nil
33
- maxlags ||= (10 * Math.log10(size)).to_i
34
-
35
- (0..maxlags).map do |i|
36
- if i == 0
37
- 1.0
38
- else
39
- m = self.mean
40
-
41
- # can't use Pearson coefficient since the mean for the lagged series should
42
- # be the same as the regular series
43
- ((self - m) * (self.lag(i) - m)).sum / self.variance_sample / (self.size - 1)
44
- end
45
- end
46
- end
47
-
48
- # Lags the series by k periods.
49
- #
50
- # The convention is to set the oldest observations (the first ones
51
- # in the series) to nil so that the size of the lagged series is the
52
- # same as the original.
53
- #
54
- # Usage:
55
- #
56
- # ts = (1..10).map { rand }.to_time_series
57
- # # => [0.69, 0.23, 0.44, 0.71, ...]
58
- #
59
- # ts.lag # => [nil, 0.69, 0.23, 0.44, ...]
60
- # ts.lag 2 # => [nil, nil, 0.69, 0.23, ...]
61
- #
62
- def lag k = 1
63
- return self if k == 0
64
-
65
- dup.tap do |lagged|
66
- (lagged.size - 1).downto k do |i|
67
- lagged[i] = lagged[i - k]
68
- end
69
-
70
- (0...k).each do |i|
71
- lagged[i] = nil
72
- end
73
- lagged.set_valid_data
74
- end
75
- end
76
-
77
- # Performs a first difference of the series.
78
- #
79
- # The convention is to set the oldest observations (the first ones
80
- # in the series) to nil so that the size of the diffed series is the
81
- # same as the original.
82
- #
83
- # Usage:
84
- #
85
- # ts = (1..10).map { rand }.to_ts
86
- # # => [0.69, 0.23, 0.44, 0.71, ...]
87
- #
88
- # ts.diff # => [nil, -0.46, 0.21, 0.27, ...]
89
- #
90
- def diff
91
- self - self.lag
92
- end
93
-
94
- # Calculates a moving average of the series using the provided
95
- # lookback argument. The lookback defaults to 10 periods.
96
- #
97
- # Usage:
98
- #
99
- # ts = (1..100).map { rand }.to_ts
100
- # # => [0.69, 0.23, 0.44, 0.71, ...]
101
- #
102
- # # first 9 observations are nil
103
- # ts.ma # => [ ... nil, 0.484... , 0.445... , 0.513 ... , ... ]
104
- def ma n = 10
105
- return mean if n >= size
106
-
107
- ([nil] * (n - 1) + (0..(size - n)).map do |i|
108
- self[i...(i + n)].inject(&:+) / n
109
- end).to_time_series
110
- end
111
-
112
- # Calculates an exponential moving average of the series using a
113
- # specified parameter. If wilder is false (the default) then the EMA
114
- # uses a smoothing value of 2 / (n + 1), if it is true then it uses the
115
- # Welles Wilder smoother of 1 / n.
116
- #
117
- # Warning for EMA usage: EMAs are unstable for small series, as they
118
- # use a lot more than n observations to calculate. The series is stable
119
- # if the size of the series is >= 3.45 * (n + 1)
120
- #
121
- # Usage:
122
- #
123
- # ts = (1..100).map { rand }.to_ts
124
- # # => [0.69, 0.23, 0.44, 0.71, ...]
125
- #
126
- # # first 9 observations are nil
127
- # ts.ema # => [ ... nil, 0.509... , 0.433..., ... ]
128
- def ema n = 10, wilder = false
129
- smoother = wilder ? 1.0 / n : 2.0 / (n + 1)
130
-
131
- # need to start everything from the first non-nil observation
132
- start = self.data.index { |i| i != nil }
133
-
134
- # first n - 1 observations are nil
135
- base = [nil] * (start + n - 1)
136
-
137
- # nth observation is just a moving average
138
- base << self[start...(start + n)].inject(0.0) { |s, a| a.nil? ? s : s + a } / n
139
-
140
- (start + n).upto size - 1 do |i|
141
- base << self[i] * smoother + (1 - smoother) * base.last
142
- end
143
-
144
- base.to_time_series
145
- end
146
-
147
- # Calculates the MACD (moving average convergence-divergence) of the time
148
- # series - this is a comparison of a fast EMA with a slow EMA.
149
- def macd fast = 12, slow = 26, signal = 9
150
- series = ema(fast) - ema(slow)
151
- [series, series.ema(signal)]
152
- end
153
-
154
- # Borrow the operations from Vector, but convert to time series
155
- def + series
156
- super.to_a.to_ts
157
- end
158
-
159
- def - series
160
- super.to_a.to_ts
161
- end
162
-
163
- def to_s
164
- sprintf("Time Series(type:%s, n:%d)[%s]", @type.to_s, @data.size,
165
- @data.collect{|d| d.nil? ? "nil":d}.join(","))
166
- end
167
- end
168
- end
169
- end
metadata.gz.sig DELETED
Binary file