From 7301c537927b71a6178cea3325c5c7275f0494eb Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 13 Jul 2014 14:11:30 -1000 Subject: [PATCH 01/12] Raising in equality precludes working with AwesomePrint Second comparison of this method in awesome_print/formatter.rb causes the crash. Without this fix, pry + awesome_print cannot be used, as even a simple case such as [1, 2, 3].to_scale will crash # Catch all method to format an arbitrary object. #------------------------------------------------------------------------------ def awesome_self(object, type) if @options[:raw] && object.instance_variables.any? awesome_object(object) elsif object == ENV awesome_hash(object.to_hash) else colorize(object.inspect.to_s, type) end end --- lib/statsample/vector.rb | 2 +- test/test_vector.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/statsample/vector.rb b/lib/statsample/vector.rb index 3f73b94..d0c570a 100644 --- a/lib/statsample/vector.rb +++ b/lib/statsample/vector.rb @@ -219,7 +219,7 @@ def box_cox_transformation(lambda) # :nodoc: # Vector equality. # Two vector will be the same if their data, missing values, type, labels are equals def ==(v2) - raise TypeError,"Argument should be a Vector" unless v2.instance_of? Statsample::Vector + return false unless v2.instance_of? Statsample::Vector @data==v2.data and @missing_values==v2.missing_values and @type==v2.type and @labels==v2.labels end diff --git a/test/test_vector.rb b/test/test_vector.rb index 9b233e1..10ebfaf 100644 --- a/test/test_vector.rb +++ b/test/test_vector.rb @@ -352,6 +352,7 @@ def test_equality v1=[1,2,3].to_vector() v2=[1,2,3].to_vector() assert_equal(v1,v2) + assert_equal(false, v1 == Object.new) end def test_vector_percentil a=[1,2,2,3,4,5,5,5,6,10].to_scale From aa0cd748354c194e732e82c84694573a517d55c3 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 13 Jul 2014 14:30:11 -1000 Subject: [PATCH 02/12] Add gemspec --- .gitignore | 19 +++++++++- Gemfile | 18 +-------- Gemfile.lock | 78 --------------------------------------- Rakefile | 1 + bin/statsample | 0 lib/statsample/version.rb | 3 ++ statsample.gemspec | 37 +++++++++++++++++++ 7 files changed, 61 insertions(+), 95 deletions(-) delete mode 100644 Gemfile.lock mode change 100644 => 100755 bin/statsample create mode 100644 lib/statsample/version.rb create mode 100644 statsample.gemspec diff --git a/.gitignore b/.gitignore index 1372732..a754343 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,21 @@ doc examples/images/* examples/*.html web/upload_task.rb -.idea \ No newline at end of file + +# From standard gemfile +*.gem +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile index 9d5105b..b42b1ad 100644 --- a/Gemfile +++ b/Gemfile @@ -1,17 +1,3 @@ source "https://www.rubygems.org" -gem 'minitest' -gem 'rdoc' -gem 'mocha', '0.14.0' #:require=>'mocha/setup' -gem 'shoulda','3.5.0' -gem 'shoulda-matchers','2.2.0' -gem 'hoe' -#gem 'bio-statsample-timeseries' -gem 'reportbuilder' -gem 'dirty-memoize' -gem 'distribution' -gem 'extendmatrix' -gem 'minimization' -gem 'rserve-client' -gem 'rubyvis' -gem 'spreadsheet' -gem 'rb-gsl' + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index d77e093..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,78 +0,0 @@ -GEM - remote: https://www.rubygems.org/ - specs: - activesupport (4.1.1) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - clbustos-rtf (0.4.2) - dirty-memoize (0.0.4) - distribution (0.7.0) - extendmatrix (0.3.1) - hoe (3.12.0) - rake (>= 0.8, < 11.0) - i18n (0.6.9) - json (1.8.1) - metaclass (0.0.4) - minimization (0.2.1) - text-table (~> 1.2) - minitest (5.3.5) - mocha (0.14.0) - metaclass (~> 0.0.1) - narray (0.6.0.9) - prawn (0.8.4) - prawn-core (>= 0.8.4, < 0.9) - prawn-layout (>= 0.8.4, < 0.9) - prawn-security (>= 0.8.4, < 0.9) - prawn-core (0.8.4) - prawn-layout (0.8.4) - prawn-security (0.8.4) - prawn-svg (0.9.1.11) - prawn (>= 0.8.4) - rake (10.3.2) - rb-gsl (1.16.0.1) - narray (>= 0.5.9) - rdoc (4.1.1) - json (~> 1.4) - reportbuilder (1.4.2) - clbustos-rtf (~> 0.4.0) - prawn (~> 0.8.4) - prawn-svg (~> 0.9.1) - text-table (~> 1.2) - rserve-client (0.3.1) - ruby-ole (1.2.11.7) - rubyvis (0.6.0) - shoulda (3.5.0) - shoulda-context (~> 1.0, >= 1.0.1) - shoulda-matchers (>= 1.4.1, < 3.0) - shoulda-context (1.2.1) - shoulda-matchers (2.2.0) - activesupport (>= 3.0.0) - spreadsheet (0.9.7) - ruby-ole (>= 1.0) - text-table (1.2.3) - thread_safe (0.3.4) - tzinfo (1.2.1) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - dirty-memoize - distribution - extendmatrix - hoe - minimization - minitest - mocha (= 0.14.0) - rb-gsl - rdoc - reportbuilder - rserve-client - rubyvis - shoulda (= 3.5.0) - shoulda-matchers (= 2.2.0) - spreadsheet diff --git a/Rakefile b/Rakefile index 46f660d..559e30d 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ require 'rubygems' require 'statsample' require 'hoe' require 'rdoc' +require "bundler/gem_tasks" Hoe.plugin :git Hoe.plugin :doofus diff --git a/bin/statsample b/bin/statsample old mode 100644 new mode 100755 diff --git a/lib/statsample/version.rb b/lib/statsample/version.rb new file mode 100644 index 0000000..ca0251a --- /dev/null +++ b/lib/statsample/version.rb @@ -0,0 +1,3 @@ +module Statsample + VERSION = "1.3.1" +end diff --git a/statsample.gemspec b/statsample.gemspec new file mode 100644 index 0000000..e31bf82 --- /dev/null +++ b/statsample.gemspec @@ -0,0 +1,37 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'statsample/version' + +Gem::Specification.new do |spec| + spec.name = 'statsample' + spec.version = '1.3.1' + spec.version = Statsample::VERSION + spec.summary = "Stats library" + spec.authors = ["Claudio Bustos", "Justin Gordon"] + spec.homepage = 'https://github.com/clbustos/statsample' + spec.license = "MIT" + spec.files = `git ls-files -z`.split("\x0") + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ["lib"] + + spec.add_development_dependency "bundler", "~> 1.5" + spec.add_development_dependency "rake" + spec.add_development_dependency 'minitest' + spec.add_development_dependency 'rdoc' + spec.add_development_dependency 'mocha', '0.14.0' #:require=>'mocha/setup' + spec.add_development_dependency 'shoulda', '3.5.0' + spec.add_development_dependency 'shoulda-matchers', '2.2.0' + + spec.add_dependency 'hoe' + spec.add_dependency 'reportbuilder' + spec.add_dependency 'dirty-memoize' + spec.add_dependency 'distribution' + spec.add_dependency 'extendmatrix' + spec.add_dependency 'minimization' + spec.add_dependency 'rserve-client' + spec.add_dependency 'rubyvis' + spec.add_dependency 'spreadsheet' + spec.add_dependency 'rb-gsl' +end From d293725f11c6a027809054cd8d504fd1c9276539 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 13 Jul 2014 18:44:53 -1000 Subject: [PATCH 03/12] Add support for summarization of correlation probabliity matrix. --- examples/correlation_matrix.rb | 6 +++ lib/statsample/bivariate.rb | 6 ++- lib/statsample/matrix.rb | 68 ++++++++++++++++++---------------- lib/statsample/shorthand.rb | 8 +++- 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/examples/correlation_matrix.rb b/examples/correlation_matrix.rb index 844e859..6feb065 100644 --- a/examples/correlation_matrix.rb +++ b/examples/correlation_matrix.rb @@ -11,6 +11,12 @@ 'd'=>rnorm(samples)) cm=cor(ds) summary(cm) + + cp = corp(ds) + summary(cp) + + cov = cov(ds) + summary(cov) end if __FILE__==$0 diff --git a/lib/statsample/bivariate.rb b/lib/statsample/bivariate.rb index d24e5ff..7e131e4 100644 --- a/lib/statsample/bivariate.rb +++ b/lib/statsample/bivariate.rb @@ -251,7 +251,11 @@ def correlation_probability_matrix(ds, tails=:both) (row==col or ds[row].type!=:scale or ds[col].type!=:scale) ? nil : prop_pearson(t_pearson(ds[row],ds[col]), v1a.size, tails) end end - Matrix.rows(rows) + m = Matrix.rows(rows) + m.extend(Statsample::CovariateMatrix) + m.fields=ds.fields + m.name = "Correlation Probability" + m end # Spearman ranked correlation coefficient (rho) between 2 vectors diff --git a/lib/statsample/matrix.rb b/lib/statsample/matrix.rb index 662bd0a..3f2eea2 100644 --- a/lib/statsample/matrix.rb +++ b/lib/statsample/matrix.rb @@ -27,14 +27,14 @@ def to_dataset if defined? :eigenpairs alias_method :eigenpairs_ruby, :eigenpairs end - + if Statsample.has_gsl? # Optimize eigenpairs of extendmatrix module using gsl def eigenpairs to_gsl.eigenpairs end end - + def eigenvalues eigenpairs.collect {|v| v[0]} end @@ -44,11 +44,11 @@ def eigenvectors def eigenvectors_matrix Matrix.columns(eigenvectors) end - - - - + + + + def to_gsl out=[] self.row_size.times{|i| @@ -76,7 +76,7 @@ class Matrix def to_gsl self end - + def to_dataset f = (self.respond_to? :fields_y) ? fields_y : column_size.times.map {|i| _("VAR_%d") % (i+1) } ds=Statsample::Dataset.new(f) @@ -91,7 +91,7 @@ def to_dataset ds.name=self.name if self.respond_to? :name ds end - + def row_size size1 end @@ -110,18 +110,18 @@ def eigenvalues def eigenvectors eigenpairs.collect {|v| v[1]} end - + # Matrix sum of squares def mssq sum=0 to_v.each {|i| sum+=i**2} sum end - + def eigenvectors_matrix eigval, eigvec= GSL::Eigen.symmv(self) GSL::Eigen::symmv_sort(eigval, eigvec, GSL::Eigen::SORT_VAL_DESC) - eigvec + eigvec end def eigenpairs eigval, eigvec= GSL::Eigen.symmv(self) @@ -130,7 +130,7 @@ def eigenpairs [eigval[i],eigvec.get_col(i)] } end - + #def eigenpairs_ruby # self.to_matrix.eigenpairs_ruby #end @@ -158,7 +158,7 @@ def total_sum module Statsample # Module to add names to X and Y fields module NamedMatrix - include Summarizable + include Summarizable def fields raise "Should be square" if !square? @@ -178,10 +178,10 @@ def fields_y=(v) @fields_y=v end def fields_x - @fields_x||=row_size.times.collect {|i| _("X%d") % i} + @fields_x||=row_size.times.collect {|i| _("X%d") % i} end def fields_y - @fields_y||=column_size.times.collect {|i| _("Y%d") % i} + @fields_y||=column_size.times.collect {|i| _("Y%d") % i} end def name @@ -195,7 +195,7 @@ def get_new_name @@named_matrix+=1 _("Matrix %d") % @@named_matrix end - + end # Module to add method for variance/covariance and correlation matrices # == Usage @@ -209,15 +209,19 @@ module CovariateMatrix # Get type of covariate matrix. Could be :covariance or :correlation def _type if row_size==column_size - if row_size.times.find {|i| self[i,i]!=1.0} - :covariance - else - :correlation + @type ||= begin + if row_size.times.find { |i| self[i, i] == 1.0 } + :correlation + elsif row_size.times.find { |i| self[i, i].nil? } + :correlation_probability + else + :covariance + end end else @type end - + end def _type=(t) @type=t @@ -233,7 +237,7 @@ def correlation end } }) - matrix.extend CovariateMatrix + matrix.extend CovariateMatrix matrix.fields_x=fields_x matrix.fields_y=fields_y matrix._type=:correlation @@ -242,19 +246,19 @@ def correlation self end end - - + + # Get variance for field k # def variance(k) submatrix([k])[0,0] end - + def get_new_name @@covariatematrix+=1 _("Covariate matrix %d") % @@covariatematrix end - + # Select a submatrix of factors. If you have a correlation matrix # with a, b and c, you could obtain a submatrix of correlations of # a and b, b and c or a and b @@ -276,24 +280,24 @@ def submatrix(rows,columns=nil) raise ArgumentError, "rows shouldn't be empty" if rows.respond_to? :size and rows.size==0 columns||=rows # Convert all fields on index - row_index=rows.collect {|v| + row_index=rows.collect {|v| r=v.is_a?(Numeric) ? v : fields_x.index(v) raise "Index #{v} doesn't exists on matrix" if r.nil? r } - column_index=columns.collect {|v| + column_index=columns.collect {|v| r=v.is_a?(Numeric) ? v : fields_y.index(v) raise "Index #{v} doesn't exists on matrix" if r.nil? r } - - + + fx=row_index.collect {|v| fields_x[v]} fy=column_index.collect {|v| fields_y[v]} - + matrix= Matrix.rows(row_index.collect {|i| row=column_index.collect {|j| self[i,j]}}) - matrix.extend CovariateMatrix + matrix.extend CovariateMatrix matrix.fields_x=fx matrix.fields_y=fy matrix._type=_type diff --git a/lib/statsample/shorthand.rb b/lib/statsample/shorthand.rb index d4956f3..aeb3a48 100644 --- a/lib/statsample/shorthand.rb +++ b/lib/statsample/shorthand.rb @@ -40,9 +40,15 @@ def names(ds) def cor(ds) Statsample::Bivariate.correlation_matrix(ds) end + + # Create a correlation probability matrix from a dataset + def corp(ds) + Statsample::Bivariate.correlation_probability_matrix(ds) + end + # Create a variance/covariance matrix from a dataset def cov(ds) - Statsample::Bivariate.covariate_matrix(ds) + Statsample::Bivariate.covariance_matrix(ds) end # Create a Statsample::Vector # Analog to R's c From 8d38876fb7da776664f299a2a0555bdefed51f18 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 13 Jul 2014 18:50:51 -1000 Subject: [PATCH 04/12] remove duplicate stting of spec.version --- statsample.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/statsample.gemspec b/statsample.gemspec index e31bf82..4ec4064 100644 --- a/statsample.gemspec +++ b/statsample.gemspec @@ -5,7 +5,6 @@ require 'statsample/version' Gem::Specification.new do |spec| spec.name = 'statsample' - spec.version = '1.3.1' spec.version = Statsample::VERSION spec.summary = "Stats library" spec.authors = ["Claudio Bustos", "Justin Gordon"] From 7c68c29622b54e8734ed25df47d67acda032e869 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 13 Jul 2014 18:51:58 -1000 Subject: [PATCH 05/12] Bump version to 1.3.2 --- lib/statsample/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statsample/version.rb b/lib/statsample/version.rb index ca0251a..bd1930b 100644 --- a/lib/statsample/version.rb +++ b/lib/statsample/version.rb @@ -1,3 +1,3 @@ module Statsample - VERSION = "1.3.1" + VERSION = "1.3.2" end From d3687d44a49be9168b819f16252b220ac274c639 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Wed, 23 Jul 2014 23:03:11 +1200 Subject: [PATCH 06/12] temp removal of gsl --- lib/statsample/bivariate.rb | 11 ++++++----- statsample.gemspec | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/statsample/bivariate.rb b/lib/statsample/bivariate.rb index 7e131e4..9a2f377 100644 --- a/lib/statsample/bivariate.rb +++ b/lib/statsample/bivariate.rb @@ -189,12 +189,13 @@ def covariance_matrix_pairwise(ds) # Correlation matrix. # Order of rows and columns depends on Dataset#fields order def correlation_matrix(ds) - vars,cases=ds.fields.size,ds.cases - if !ds.has_missing_data? and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases) - cm=correlation_matrix_optimized(ds) - else + # Todo uncomment out this code + # vars,cases=ds.fields.size,ds.cases + # if !ds.has_missing_data? and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases) + # cm=correlation_matrix_optimized(ds) + # else cm=correlation_matrix_pairwise(ds) - end + # end cm.extend(Statsample::CovariateMatrix) cm.fields=ds.fields cm diff --git a/statsample.gemspec b/statsample.gemspec index 4ec4064..134cef4 100644 --- a/statsample.gemspec +++ b/statsample.gemspec @@ -32,5 +32,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'rserve-client' spec.add_dependency 'rubyvis' spec.add_dependency 'spreadsheet' - spec.add_dependency 'rb-gsl' + # spec.add_dependency 'rb-gsl' end From 7470e70754989e1ed45162ce115cbb14a33fba2e Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Wed, 23 Jul 2014 23:24:22 +1200 Subject: [PATCH 07/12] add back gsl gem --- statsample.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statsample.gemspec b/statsample.gemspec index 134cef4..4ec4064 100644 --- a/statsample.gemspec +++ b/statsample.gemspec @@ -32,5 +32,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'rserve-client' spec.add_dependency 'rubyvis' spec.add_dependency 'spreadsheet' - # spec.add_dependency 'rb-gsl' + spec.add_dependency 'rb-gsl' end From 3aefa5f9842479f7641dd3f9fc636b70bcda1176 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Thu, 24 Jul 2014 08:23:59 +1200 Subject: [PATCH 08/12] remove commenting of gsl --- lib/statsample/bivariate.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/statsample/bivariate.rb b/lib/statsample/bivariate.rb index 9a2f377..7e131e4 100644 --- a/lib/statsample/bivariate.rb +++ b/lib/statsample/bivariate.rb @@ -189,13 +189,12 @@ def covariance_matrix_pairwise(ds) # Correlation matrix. # Order of rows and columns depends on Dataset#fields order def correlation_matrix(ds) - # Todo uncomment out this code - # vars,cases=ds.fields.size,ds.cases - # if !ds.has_missing_data? and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases) - # cm=correlation_matrix_optimized(ds) - # else + vars,cases=ds.fields.size,ds.cases + if !ds.has_missing_data? and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases) + cm=correlation_matrix_optimized(ds) + else cm=correlation_matrix_pairwise(ds) - # end + end cm.extend(Statsample::CovariateMatrix) cm.fields=ds.fields cm From c2d8914b09774e81fa4dbbc2f2856cf49c2560b0 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sat, 26 Jul 2014 14:22:25 +1200 Subject: [PATCH 09/12] removed hoe as using gemspec --- statsample.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/statsample.gemspec b/statsample.gemspec index 4ec4064..c63faf0 100644 --- a/statsample.gemspec +++ b/statsample.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'shoulda', '3.5.0' spec.add_development_dependency 'shoulda-matchers', '2.2.0' - spec.add_dependency 'hoe' spec.add_dependency 'reportbuilder' spec.add_dependency 'dirty-memoize' spec.add_dependency 'distribution' From 4176d115aa4b1c53fa62a7404b62f86a966b4888 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sat, 26 Jul 2014 17:13:08 +1200 Subject: [PATCH 10/12] Added Russell Smith to authors in Gemspec --- statsample.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statsample.gemspec b/statsample.gemspec index c63faf0..712f6dd 100644 --- a/statsample.gemspec +++ b/statsample.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |spec| spec.name = 'statsample' spec.version = Statsample::VERSION spec.summary = "Stats library" - spec.authors = ["Claudio Bustos", "Justin Gordon"] + spec.authors = ["Claudio Bustos", "Justin Gordon", "Russell Smith"] spec.homepage = 'https://github.com/clbustos/statsample' spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0") From a310c942a5a853716003526947d9a429afd29ea5 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Tue, 11 Nov 2014 14:08:34 -1000 Subject: [PATCH 11/12] Raise error indicating what is cauing computation to fail This is the computation that fails def t_r(r,size) r * Math::sqrt(((size)-2).to_f / (1 - r**2)) end --- lib/statsample/bivariate.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/statsample/bivariate.rb b/lib/statsample/bivariate.rb index 7e131e4..ed04c3c 100644 --- a/lib/statsample/bivariate.rb +++ b/lib/statsample/bivariate.rb @@ -71,6 +71,8 @@ def t_pearson(v1,v2) # giving r and vector size # Source : http://faculty.chass.ncsu.edu/garson/PA765/correl.htm def t_r(r,size) + raise "In computing value for t test for a pearson correlation, invalid size of series: #{size}" if size <= 2 + raise "In computing value for t test for a pearson correlation, invalid value of r: #{r}" if r >= 1 r * Math::sqrt(((size)-2).to_f / (1 - r**2)) end # Retrieves the probability value (a la SPSS) From e46a73fd029b1343fcc42963fa24c3f178db1069 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Tue, 11 Nov 2014 14:35:43 -1000 Subject: [PATCH 12/12] Substitute value just under 1 if R >= 1 --- lib/statsample/bivariate.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/statsample/bivariate.rb b/lib/statsample/bivariate.rb index ed04c3c..5115a16 100644 --- a/lib/statsample/bivariate.rb +++ b/lib/statsample/bivariate.rb @@ -72,7 +72,11 @@ def t_pearson(v1,v2) # Source : http://faculty.chass.ncsu.edu/garson/PA765/correl.htm def t_r(r,size) raise "In computing value for t test for a pearson correlation, invalid size of series: #{size}" if size <= 2 - raise "In computing value for t test for a pearson correlation, invalid value of r: #{r}" if r >= 1 + raise "In computing value for t test for a pearson correlation, invalid value of r: #{r}" if r >= 1.1 + if r >= 1 + puts "StatSample::Bivariate#t_r: got an R value > 1 (#{r}), so substituting 0.999999" + r = 0.999999 + end r * Math::sqrt(((size)-2).to_f / (1 - r**2)) end # Retrieves the probability value (a la SPSS)