statsample 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad9180f3e25cf0cc125d1e4a0e534b89bdaf4c11
4
- data.tar.gz: cd72f54dcbf15cdf6413daf54551c8b9820d50fd
3
+ metadata.gz: ee62b72f947f9760824885a479c92ce6dbc55127
4
+ data.tar.gz: 7cb2c7057856eee78f69be2f7c1e43671cc8007e
5
5
  SHA512:
6
- metadata.gz: a001eb384addd6ed71907135a89dd72adaab3b062925fbdeb2b86ec8070cc227c0b9da2be6d4143266091b4e020d37603dbf9b9e2965a410bbac1c8d58fbf4e4
7
- data.tar.gz: 2069ae723e70c28a00b0f058aac934ff3894792c3cb5d5467efdcc371f28dac9e52c41ea4b0be6410c9a69c58b3c305fbbca1ddb4ded6bc603d274769e128f4f
6
+ metadata.gz: 26b9d9aab40c4dc700fc4632a30cd195f5f0f0dfe6ab36a84d055f5d0e22ba7992c143ac2507069c02e3ec6e3b02b31f20ae1bf4c1f47a8846339c6d0e0b67b6
7
+ data.tar.gz: 8eeac7c1f6aca3ed959ff15cfd97407876d46dfb8d9adf13aa892831772b02209142d73a46ac1581e848cf020b86cfccb93e21bd9f450da106d08ed755d5bd1b
@@ -1,14 +1,11 @@
1
1
  language:
2
2
  ruby
3
3
 
4
- env:
5
- - CPLUS_INCLUDE_PATH=/usr/include/atlas C_INCLUDE_PATH=/usr/include/atlas
6
-
7
4
  rvm:
8
- - '1.9.3'
9
5
  - '2.0'
10
6
  - '2.1'
11
7
  - '2.2'
8
+ - '2.3.0'
12
9
 
13
10
  matrix:
14
11
  fast_finish:
@@ -18,11 +15,9 @@ script: "bundle exec rake test"
18
15
 
19
16
  install:
20
17
  - gem install bundler
21
- - ./.build.sh
22
18
  - bundle install
23
19
 
24
20
  before_install:
25
21
  - sudo apt-get update -qq
26
- - sudo apt-get install -qq libatlas-base-dev
27
22
  - sudo apt-get install -y libgsl0-dev r-base r-base-dev
28
23
  - sudo Rscript -e "install.packages(c('Rserve','irr'),,'http://cran.us.r-project.org')"
@@ -2,27 +2,11 @@
2
2
 
3
3
  ## Installing statsample development dependencies
4
4
 
5
- If you want to run the full test suite, you will need the latest unreleased nmatrix and gsl-nmatrix ruby gems. They will be released upstream soon but please follow this procdure for now.
5
+ Keep in mind that either nmatrix OR rb-gsl are NOT NECESSARY for using statsample. They are just required for an optional speed up.
6
6
 
7
- Keep in mind that either nmatrix OR gsl-nmatrix are NOT NECESSARY for using statsample. They are just required for an optional speed up.
7
+ Statsample also works with [rb-gsl](https://github.com/sciruby/rb-gsl).
8
8
 
9
- Statsample also works with [rb-gsl](https://github.com/blackwinter/rb-gsl), though installing that will cause a problem if you have any nmatrix dependent code because narray and nmatrix have a namespace problem.
10
-
11
- To install dependencies, execute the following commands:
12
-
13
- `export CPLUS_INCLUDE_PATH=/usr/include/atlas`
14
- `export C_INCLUDE_PATH=/usr/include/atlas`
15
- `sudo apt-get update -qq`
16
- `sudo apt-get install -qq libatlas-base-dev`
17
- `sudo apt-get --purge remove liblapack-dev liblapack3 liblapack3gf`
18
- `sudo apt-get install -y libgsl0-dev r-base r-base-dev`
19
- `sudo Rscript -e "install.packages(c('Rserve','irr'),,'http://cran.us.r-project.org')"`
20
-
21
- Then execute the .build.sh script to clone and install the latest nmatrix and gsl-nmatrix on your system:
22
-
23
- `./.build.sh`
24
-
25
- Then finally install remaining dependencies:
9
+ Install dependencies:
26
10
 
27
11
  `bundle install`
28
12
 
@@ -1,3 +1,6 @@
1
+ === 2.0.2 / 2016-03-11
2
+ * Update dependencies (spreadsheet, GSL)
3
+
1
4
  === 2.0.1 / 2015-08-19
2
5
  * Cleaned legacy containers in favor of `Daru::DataFrame` and `Daru::Vector`.
3
6
 
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift(File.dirname(__FILE__)+'/../lib')
3
+ require 'statsample'
4
+
5
+ Statsample::Analysis.store(Statsample::Test::ChiSquare) do
6
+ # Collect the two vectors with the categorical data (raw number of occurences) into one matrix. Here
7
+ #--------------------------------------------
8
+ #| category | observation 1 | observation 2 |
9
+ #|------------------------------------------|
10
+ #| A | 100 | 20 |
11
+ #| B | 50 | 70 |
12
+ #| C | 30 | 100 |
13
+ #|------------------------------------------|
14
+ #
15
+ m=Matrix[[100, 50, 30],[20, 70, 100]]
16
+ x_2=Statsample::Test.chi_square(m)
17
+ # after the test is done, look at the p-value.
18
+ puts x_2.probability
19
+ end
20
+
21
+ if __FILE__==$0
22
+ Statsample::Analysis.run_batch
23
+ end
@@ -59,13 +59,13 @@ class Array
59
59
  end
60
60
 
61
61
  def mean
62
- self.sum / size
62
+ sum.fdiv(size)
63
63
  end
64
64
 
65
65
  # Calcualte sum of squares
66
66
  def sum_of_squares(m=nil)
67
67
  m ||= mean
68
- self.inject(0) {|a,x| a + (x-m).square }
68
+ inject(0) {|a,x| a + (x-m).square }
69
69
  end
70
70
 
71
71
  # Calculate sample variance
@@ -124,6 +124,7 @@ module Statsample
124
124
  cv = "@@#{library}"
125
125
  unless class_variable_defined? cv
126
126
  begin
127
+ gem library.to_s # activate gem
127
128
  require library.to_s
128
129
  class_variable_set(cv, true)
129
130
  rescue LoadError
@@ -1,9 +1,26 @@
1
1
  module Statsample
2
2
  module Test
3
3
  module ChiSquare
4
- class WithMatrix
4
+ module Shared
5
5
  attr_reader :df
6
6
  attr_reader :value
7
+
8
+ def to_f
9
+ @value
10
+ end
11
+
12
+ def chi_square
13
+ @value
14
+ end
15
+
16
+ def probability
17
+ 1-Distribution::ChiSquare.cdf(@value.to_f,@df)
18
+ end
19
+ end
20
+
21
+ class WithMatrix
22
+ include Statsample::Test::ChiSquare::Shared
23
+
7
24
  def initialize(observed, expected=nil)
8
25
  @observed=observed
9
26
  @expected=expected or calculate_expected
@@ -11,33 +28,46 @@ module Statsample
11
28
  @df=(@observed.row_size-1)*(@observed.column_size-1)
12
29
  @value=compute_chi
13
30
  end
31
+
14
32
  def calculate_expected
15
33
  sum=@observed.total_sum
16
34
  @expected=Matrix.rows( @observed.row_size.times.map {|i|
17
35
  @observed.column_size.times.map {|j|
18
36
  (@observed.row_sum[i].quo(sum) * @observed.column_sum[j].quo(sum))*sum
19
37
  }
20
- })
21
- end
22
- def to_f
23
- @value
24
- end
25
- def chi_square
26
- @value
27
- end
28
- def probability
29
- 1-Distribution::ChiSquare.cdf(@value.to_f,@df)
38
+ })
30
39
  end
40
+
31
41
  def compute_chi
32
- sum=0
33
- (0...@observed.row_size).each {|i|
34
- (0...@observed.column_size).each {|j|
42
+ sum=0
43
+ (0...@observed.row_size).each {|i|
44
+ (0...@observed.column_size).each {|j|
35
45
  sum+=((@observed[i, j] - @expected[i,j])**2).quo(@expected[i,j])
36
- }
37
46
  }
38
- sum
47
+ }
48
+ sum
49
+ end
50
+ end
51
+
52
+ class WithVector
53
+ include Statsample::Test::ChiSquare::Shared
54
+
55
+ def initialize(observed, expected)
56
+ @observed = observed
57
+ @expected = expected
58
+ raise "Observed size!=expected size" if @observed.size!=@expected.size
59
+ @df = @observed.size - 1
60
+ @value = compute_chi
61
+ end
62
+
63
+ def compute_chi
64
+ sum=0
65
+ (0...@observed.size).each {|i|
66
+ sum+=((@observed[i] - @expected[i])**2).quo(@expected[i])
67
+ }
68
+ sum
39
69
  end
40
70
  end
41
71
  end
42
72
  end
43
- end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module Statsample
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -61,7 +61,7 @@ Gem::Specification.new do |s|
61
61
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
62
62
 
63
63
  s.add_runtime_dependency 'daru', '~> 0.1'
64
- s.add_runtime_dependency 'spreadsheet', '~> 1.0.3'
64
+ s.add_runtime_dependency 'spreadsheet', '~> 1.1'
65
65
  s.add_runtime_dependency 'reportbuilder', '~> 1.4'
66
66
  s.add_runtime_dependency 'minimization', '~> 0.2'
67
67
  s.add_runtime_dependency 'dirty-memoize', '~> 0.0.4'
@@ -79,6 +79,6 @@ Gem::Specification.new do |s|
79
79
  s.add_development_dependency 'minitest', '~> 5.7'
80
80
  s.add_development_dependency 'gettext', '~> 3.1'
81
81
  s.add_development_dependency 'mocha', '~> 1.1'
82
- s.add_development_dependency 'nmatrix', '~> 0.1.0'
83
- s.add_development_dependency 'rb-gsl', '~> 1.16'
82
+ s.add_development_dependency 'nmatrix', '~> 0.2.1'
83
+ s.add_development_dependency 'gsl', '~> 2.1'
84
84
  end
@@ -53,7 +53,7 @@ class StatsampleFactorTestCase < Minitest::Test
53
53
 
54
54
  def test_parallelanalysis
55
55
  pa = Statsample::Factor::ParallelAnalysis.with_random_data(305, 8, iterations: 100, percentil: 95)
56
- assert_in_delta(1.2454, pa.ds_eigenvalues[:ev_00001].mean, 0.01)
56
+ assert_in_delta(1.2454, pa.ds_eigenvalues[:ev_00001].mean, 0.05)
57
57
  assert_in_delta(1.1542, pa.ds_eigenvalues[:ev_00002].mean, 0.01)
58
58
  assert_in_delta(1.0836, pa.ds_eigenvalues[:ev_00003].mean, 0.01)
59
59
  assert(pa.summary.size > 0)
@@ -23,6 +23,20 @@ class StatsampleTestTestCase < Minitest::Test
23
23
  assert_equal(6, chi.df)
24
24
  end
25
25
 
26
+ def test_chi_square_vector
27
+ observed = Vector[20,30,15]
28
+ expected = Vector[20,20,20]
29
+ assert_nothing_raised do
30
+ Statsample::Test.chi_square(observed, expected)
31
+ end
32
+ chi = Statsample::Test.chi_square(observed, expected)
33
+
34
+ assert_in_delta(6.25, chi.chi_square, 0.0001)
35
+ assert_in_delta(0.04393, chi.probability, 0.00001)
36
+
37
+ assert_equal(2, chi.df)
38
+ end
39
+
26
40
  def test_u_mannwhitney
27
41
  a = Daru::Vector.new([1, 2, 3, 4, 5, 6])
28
42
  b = Daru::Vector.new([0, 5, 7, 9, 10, 11])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-19 00:00:00.000000000 Z
12
+ date: 2016-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daru
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 1.0.3
34
+ version: '1.1'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 1.0.3
41
+ version: '1.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: reportbuilder
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -269,28 +269,28 @@ dependencies:
269
269
  requirements:
270
270
  - - "~>"
271
271
  - !ruby/object:Gem::Version
272
- version: 0.1.0
272
+ version: 0.2.1
273
273
  type: :development
274
274
  prerelease: false
275
275
  version_requirements: !ruby/object:Gem::Requirement
276
276
  requirements:
277
277
  - - "~>"
278
278
  - !ruby/object:Gem::Version
279
- version: 0.1.0
279
+ version: 0.2.1
280
280
  - !ruby/object:Gem::Dependency
281
- name: rb-gsl
281
+ name: gsl
282
282
  requirement: !ruby/object:Gem::Requirement
283
283
  requirements:
284
284
  - - "~>"
285
285
  - !ruby/object:Gem::Version
286
- version: '1.16'
286
+ version: '2.1'
287
287
  type: :development
288
288
  prerelease: false
289
289
  version_requirements: !ruby/object:Gem::Requirement
290
290
  requirements:
291
291
  - - "~>"
292
292
  - !ruby/object:Gem::Version
293
- version: '1.16'
293
+ version: '2.1'
294
294
  description: |
295
295
  A suite for basic and advanced statistics on Ruby. Tested on CRuby 1.9.3, 2.0.0
296
296
  and 2.1.1. See `.travis.yml` for more information.
@@ -328,7 +328,6 @@ extra_rdoc_files:
328
328
  - README.md
329
329
  - references.txt
330
330
  files:
331
- - ".build.sh"
332
331
  - ".gitignore"
333
332
  - ".travis.yml"
334
333
  - CONTRIBUTING.md
@@ -351,6 +350,7 @@ files:
351
350
  - data/locale/es/LC_MESSAGES/statsample.mo
352
351
  - doc_latex/manual/equations.tex
353
352
  - examples/boxplot.rb
353
+ - examples/chisquare_test.rb
354
354
  - examples/correlation_matrix.rb
355
355
  - examples/dataset.rb
356
356
  - examples/dominance_analysis.rb
@@ -508,4 +508,46 @@ rubygems_version: 2.4.5
508
508
  signing_key:
509
509
  specification_version: 4
510
510
  summary: A suite for basic and advanced statistics on Ruby
511
- test_files: []
511
+ test_files:
512
+ - test/fixtures/bank2.dat
513
+ - test/fixtures/correlation_matrix.rb
514
+ - test/fixtures/hartman_23.matrix
515
+ - test/fixtures/stock_data.csv
516
+ - test/fixtures/tetmat_matrix.txt
517
+ - test/fixtures/tetmat_test.txt
518
+ - test/helpers_tests.rb
519
+ - test/test_analysis.rb
520
+ - test/test_anova_contrast.rb
521
+ - test/test_anovaoneway.rb
522
+ - test/test_anovatwoway.rb
523
+ - test/test_anovatwowaywithdataset.rb
524
+ - test/test_anovawithvectors.rb
525
+ - test/test_awesome_print_bug.rb
526
+ - test/test_bartlettsphericity.rb
527
+ - test/test_bivariate.rb
528
+ - test/test_codification.rb
529
+ - test/test_crosstab.rb
530
+ - test/test_dominance_analysis.rb
531
+ - test/test_factor.rb
532
+ - test/test_factor_map.rb
533
+ - test/test_factor_pa.rb
534
+ - test/test_ggobi.rb
535
+ - test/test_gsl.rb
536
+ - test/test_histogram.rb
537
+ - test/test_matrix.rb
538
+ - test/test_multiset.rb
539
+ - test/test_regression.rb
540
+ - test/test_reliability.rb
541
+ - test/test_reliability_icc.rb
542
+ - test/test_reliability_skillscale.rb
543
+ - test/test_resample.rb
544
+ - test/test_srs.rb
545
+ - test/test_statistics.rb
546
+ - test/test_stest.rb
547
+ - test/test_stratified.rb
548
+ - test/test_test_f.rb
549
+ - test/test_test_kolmogorovsmirnov.rb
550
+ - test/test_test_t.rb
551
+ - test/test_umannwhitney.rb
552
+ - test/test_vector.rb
553
+ - test/test_wilcoxonsignedrank.rb
data/.build.sh DELETED
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
-
3
- git clone https://github.com/SciRuby/nmatrix.git
4
- cd nmatrix
5
- gem build nmatrix.gemspec
6
- gem install nmatrix-0.1.0.gem
7
- cd ..
8
- rm -rf nmatrix
9
- git clone https://github.com/v0dro/gsl-nmatrix
10
- cd gsl-nmatrix
11
- gem build gsl-nmatrix.gemspec
12
- gem install gsl-nmatrix-1.17.gem
13
- cd ..
14
- rm -rf gsl-nmatrix
15
-