statsample 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.build.sh +15 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +19 -7
  5. data/CONTRIBUTING.md +33 -0
  6. data/History.txt +5 -0
  7. data/README.md +41 -53
  8. data/benchmarks/correlation_matrix_15_variables.rb +6 -5
  9. data/benchmarks/correlation_matrix_5_variables.rb +6 -5
  10. data/benchmarks/correlation_matrix_methods/correlation_matrix.rb +23 -26
  11. data/examples/boxplot.rb +17 -5
  12. data/examples/correlation_matrix.rb +36 -7
  13. data/examples/dataset.rb +25 -5
  14. data/examples/dominance_analysis.rb +8 -7
  15. data/examples/dominance_analysis_bootstrap.rb +16 -11
  16. data/examples/histogram.rb +16 -2
  17. data/examples/icc.rb +5 -6
  18. data/examples/levene.rb +17 -3
  19. data/examples/multiple_regression.rb +6 -3
  20. data/examples/parallel_analysis.rb +11 -6
  21. data/examples/polychoric.rb +26 -13
  22. data/examples/principal_axis.rb +8 -4
  23. data/examples/reliability.rb +10 -10
  24. data/examples/scatterplot.rb +8 -0
  25. data/examples/t_test.rb +7 -0
  26. data/examples/u_test.rb +10 -2
  27. data/examples/vector.rb +9 -6
  28. data/examples/velicer_map_test.rb +12 -8
  29. data/lib/statsample.rb +13 -47
  30. data/lib/statsample/analysis/suite.rb +1 -1
  31. data/lib/statsample/anova/oneway.rb +6 -6
  32. data/lib/statsample/anova/twoway.rb +26 -24
  33. data/lib/statsample/bivariate.rb +78 -61
  34. data/lib/statsample/bivariate/pearson.rb +2 -2
  35. data/lib/statsample/codification.rb +45 -32
  36. data/lib/statsample/converter/csv.rb +15 -53
  37. data/lib/statsample/converter/spss.rb +6 -5
  38. data/lib/statsample/converters.rb +50 -211
  39. data/lib/statsample/crosstab.rb +26 -25
  40. data/lib/statsample/daru.rb +117 -0
  41. data/lib/statsample/dataset.rb +70 -942
  42. data/lib/statsample/dominanceanalysis.rb +16 -17
  43. data/lib/statsample/dominanceanalysis/bootstrap.rb +26 -28
  44. data/lib/statsample/factor/parallelanalysis.rb +17 -19
  45. data/lib/statsample/factor/pca.rb +21 -20
  46. data/lib/statsample/factor/principalaxis.rb +3 -3
  47. data/lib/statsample/graph/boxplot.rb +8 -16
  48. data/lib/statsample/graph/histogram.rb +4 -4
  49. data/lib/statsample/graph/scatterplot.rb +8 -7
  50. data/lib/statsample/histogram.rb +128 -119
  51. data/lib/statsample/matrix.rb +20 -16
  52. data/lib/statsample/multiset.rb +39 -38
  53. data/lib/statsample/regression.rb +3 -3
  54. data/lib/statsample/regression/multiple.rb +8 -10
  55. data/lib/statsample/regression/multiple/alglibengine.rb +96 -89
  56. data/lib/statsample/regression/multiple/baseengine.rb +32 -32
  57. data/lib/statsample/regression/multiple/gslengine.rb +33 -36
  58. data/lib/statsample/regression/multiple/matrixengine.rb +7 -9
  59. data/lib/statsample/regression/multiple/rubyengine.rb +39 -41
  60. data/lib/statsample/reliability.rb +23 -25
  61. data/lib/statsample/reliability/icc.rb +8 -7
  62. data/lib/statsample/reliability/multiscaleanalysis.rb +14 -12
  63. data/lib/statsample/reliability/scaleanalysis.rb +58 -60
  64. data/lib/statsample/reliability/skillscaleanalysis.rb +34 -29
  65. data/lib/statsample/resample.rb +1 -1
  66. data/lib/statsample/shorthand.rb +29 -25
  67. data/lib/statsample/test/kolmogorovsmirnov.rb +5 -3
  68. data/lib/statsample/test/levene.rb +28 -27
  69. data/lib/statsample/test/t.rb +7 -9
  70. data/lib/statsample/test/umannwhitney.rb +28 -28
  71. data/lib/statsample/test/wilcoxonsignedrank.rb +45 -43
  72. data/lib/statsample/vector.rb +70 -1013
  73. data/lib/statsample/version.rb +1 -1
  74. data/statsample.gemspec +12 -16
  75. data/test/helpers_tests.rb +1 -1
  76. data/test/test_analysis.rb +17 -17
  77. data/test/test_anova_contrast.rb +6 -6
  78. data/test/test_anovatwowaywithdataset.rb +8 -8
  79. data/test/test_anovawithvectors.rb +8 -8
  80. data/test/test_awesome_print_bug.rb +1 -1
  81. data/test/test_bartlettsphericity.rb +4 -4
  82. data/test/test_bivariate.rb +48 -43
  83. data/test/test_codification.rb +33 -33
  84. data/test/test_crosstab.rb +9 -9
  85. data/test/test_dataset.rb +28 -458
  86. data/test/test_factor.rb +46 -38
  87. data/test/test_factor_pa.rb +22 -13
  88. data/test/test_ggobi.rb +4 -4
  89. data/test/test_gsl.rb +4 -4
  90. data/test/test_histogram.rb +3 -3
  91. data/test/test_matrix.rb +13 -13
  92. data/test/test_multiset.rb +103 -91
  93. data/test/test_regression.rb +57 -52
  94. data/test/test_reliability.rb +55 -45
  95. data/test/test_reliability_icc.rb +8 -8
  96. data/test/test_reliability_skillscale.rb +26 -24
  97. data/test/test_resample.rb +1 -1
  98. data/test/test_statistics.rb +3 -13
  99. data/test/test_stest.rb +9 -9
  100. data/test/test_stratified.rb +3 -3
  101. data/test/test_test_t.rb +12 -12
  102. data/test/test_umannwhitney.rb +2 -2
  103. data/test/test_vector.rb +76 -613
  104. data/test/test_wilcoxonsignedrank.rb +4 -4
  105. metadata +57 -28
  106. data/lib/statsample/rserve_extension.rb +0 -20
  107. data/lib/statsample/vector/gsl.rb +0 -106
  108. data/test/fixtures/repeated_fields.csv +0 -7
  109. data/test/fixtures/scientific_notation.csv +0 -4
  110. data/test/fixtures/test_csv.csv +0 -7
  111. data/test/fixtures/test_xls.xls +0 -0
  112. data/test/test_csv.rb +0 -63
  113. data/test/test_rserve_extension.rb +0 -42
  114. data/test/test_xls.rb +0 -52
@@ -1,14 +1,34 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
+ # == Description
4
+ #
5
+ # This example demonstrates creation of basic Vectors and DataFrames.
3
6
  require 'statsample'
4
7
 
5
- Statsample::Analysis.store(Statsample::Dataset) do
6
- samples=1000
7
- a=Statsample::Vector.new_numeric(samples) {r=rand(5); r==4 ? nil: r}
8
- b=Statsample::Vector.new_numeric(samples) {r=rand(5); r==4 ? nil: r}
8
+ Statsample::Analysis.store(Daru::DataFrame) do
9
+ # We set lazy_update to *true* so that time is not wasted in updating
10
+ # metdata every time an assignment happens.
11
+ Daru.lazy_update = true
9
12
 
10
- ds={'a'=>a,'b'=>b}.to_dataset
13
+ samples = 1000
14
+
15
+ # The 'new_with_size' function lets you specify the size of the
16
+ # vector as the argument and the block specifies how each element
17
+ # of the vector will be created.
18
+ a = Daru::Vector.new_with_size(samples) {r=rand(5); r==4 ? nil: r}
19
+ b = Daru::Vector.new_with_size(samples) {r=rand(5); r==4 ? nil: r}
20
+
21
+ # Pass the Daru::Vector objects in a Hash to the DataFrame constructor
22
+ # to make a DataFrame.
23
+ #
24
+ # The *order* option lets you specify the way the vectors in the Hash
25
+ # will be ordered. Not specifyin this will order vectors in alphabetical
26
+ # order by default.
27
+ ds = Daru::DataFrame.new({:a=>a,:b=>b}, order: [:b, :a])
11
28
  summary(ds)
29
+
30
+ # Reset lazy_update to *false* to prevent other code from breaking.
31
+ Daru.lazy_update = false
12
32
  end
13
33
 
14
34
  if __FILE__==$0
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
3
 
4
+ # == Description
5
+ #
6
+ # Dominance Analysis with statsample
4
7
  require 'statsample'
5
-
6
-
7
8
  Statsample::Analysis.store(Statsample::DominanceAnalysis) do
8
9
  sample=300
9
10
  a=rnorm(sample)
@@ -11,17 +12,17 @@ Statsample::Analysis.store(Statsample::DominanceAnalysis) do
11
12
  c=rnorm(sample)
12
13
  d=rnorm(sample)
13
14
 
14
- ds={'a'=>a,'b'=>b,'cc'=>c,'d'=>d}.to_dataset
15
+ ds = Daru::DataFrame.new({:a => a,:b => b,:cc => c,:d => d}, clone: false)
15
16
  attach(ds)
16
- ds['y']=a*5+b*3+cc*2+d+rnorm(300)
17
+ ds[:y]=a*5 + b*3 + cc*2 + d + rnorm(300)
17
18
  cm=cor(ds)
18
19
  summary(cm)
19
- lr=lr(ds,'y')
20
+ lr=lr(ds,:y)
20
21
  summary(lr)
21
- da=dominance_analysis(ds,'y')
22
+ da=dominance_analysis(ds,:y)
22
23
  summary(da)
23
24
 
24
- da=dominance_analysis(ds,'y',:name=>"Dominance Analysis using group of predictors", :predictors=>['a', 'b', %w{cc d}])
25
+ da = dominance_analysis(ds,:y,:name=>"Dominance Analysis using group of predictors", :predictors=>[:a, :b, [:cc, :d]])
25
26
  summary(da)
26
27
  end
27
28
 
@@ -3,29 +3,34 @@ $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
3
  require 'statsample'
4
4
 
5
5
  Statsample::Analysis.store(Statsample::DominanceAnalysis::Bootstrap) do
6
-
6
+ # Remember to call *update* after an assignment/deletion cycle if lazy_update
7
+ # is *false*.
8
+ Daru.lazy_update = true
9
+
7
10
  sample=300
8
11
  a=rnorm(sample)
9
12
  b=rnorm(sample)
10
13
  c=rnorm(sample)
11
14
  d=rnorm(sample)
12
- a.name="a"
13
- b.name="b"
14
- c.name="c"
15
- d.name="d"
15
+ a.rename :a
16
+ b.rename :b
17
+ c.rename :c
18
+ d.rename :d
16
19
 
17
- ds={'a'=>a,'b'=>b,'cc'=>c,'d'=>d}.to_dataset
20
+ ds = Daru::DataFrame.new({:a => a,:b => b,:cc => c,:d => d})
18
21
  attach(ds)
19
- ds['y1']=a*5+b*2+cc*2+d*2+rnorm(sample,0,10)
20
- ds['y2']=a*10+rnorm(sample)
22
+ ds[:y1] = a*5 + b*2 + cc*2 + d*2 + rnorm(sample,0,10)
23
+ ds[:y2] = a*10 + rnorm(sample)
21
24
 
22
- dab=dominance_analysis_bootstrap(ds, ['y1','y2'], :debug=>true)
25
+ dab=dominance_analysis_bootstrap(ds, [:y1,:y2], :debug=>true)
23
26
  dab.bootstrap(100,nil)
24
27
  summary(dab)
25
- ds2=ds['a'..'y1']
26
- dab2=dominance_analysis_bootstrap(ds2, 'y1', :debug=>true)
28
+ ds2=ds[:a..:y1]
29
+ dab2=dominance_analysis_bootstrap(ds2, :y1, :debug=>true)
27
30
  dab2.bootstrap(100,nil)
28
31
  summary(dab2)
32
+
33
+ Daru.lazy_update = false
29
34
  end
30
35
 
31
36
  if __FILE__==$0
@@ -1,12 +1,26 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
+
4
+ # == Description
5
+ #
6
+ # This example demonstrates how a histogram can be created
7
+ # with statsample.
8
+ #
9
+ # The 'histogram' function creates a histogram by using the
10
+ # Statsample::Graph::Histogram class. This class accepts data
11
+ # in a Daru::Vector (as created by `rnorm`).
12
+ #
13
+ # A line showing normal distribution can be drawn by setting
14
+ # the `:line_normal_distribution` option to *true*.
15
+ #
16
+ # See this notebook for an illustration:
17
+ # http://nbviewer.ipython.org/github/SciRuby/sciruby-notebooks/blob/master/statistics/Creating%20a%20Histogram.ipynb
3
18
  require 'statsample'
4
19
 
5
20
  Statsample::Analysis.store(Statsample::Graph::Histogram) do
6
- histogram(rnorm(3000,0,20))
21
+ histogram(rnorm(3000,0,20), :line_normal_distribution => true)
7
22
  end
8
23
 
9
-
10
24
  if __FILE__==$0
11
25
  Statsample::Analysis.run
12
26
  end
@@ -6,18 +6,17 @@ require 'statsample'
6
6
  Statsample::Analysis.store(Statsample::Reliability::ICC) do
7
7
 
8
8
  size=1000
9
- a=Statsample::Vector.new_numeric(size) {rand(10)}
10
- b=a.recode{|i|i+rand(4)-2}
11
- c=a.recode{|i|i+rand(4)-2}
12
- d=a.recode{|i|i+rand(4)-2}
13
- @ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
9
+ a = Daru::Vector.new_with_size(size) {rand(10)}
10
+ b = a.recode{|i|i+rand(4)-2}
11
+ c = a.recode{|i|i+rand(4)-2}
12
+ d = a.recode{|i|i+rand(4)-2}
13
+ @ds = Daru::DataFrame.new({:a => a,:b => b,:c => c,:d => d})
14
14
  @icc=Statsample::Reliability::ICC.new(@ds)
15
15
  summary(@icc)
16
16
  @icc.type=:icc_3_1
17
17
  summary(@icc)
18
18
  @icc.type=:icc_a_k
19
19
  summary(@icc)
20
-
21
20
  end
22
21
 
23
22
  if __FILE__==$0
@@ -1,15 +1,29 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
3
 
4
+ # == Description
5
+ #
6
+ # This example demonstrates how a levene test can be performed by
7
+ # using Daru::Vector and the Statsample::Test::Levene class.
8
+ #
9
+ # Levene's test is an inferential statistic used to assess the
10
+ # equality of variances for a variable calculated for two or more groups.
11
+ #
12
+ # == References
13
+ #
14
+ # http://en.wikipedia.org/wiki/Levene%27s_test
4
15
  require 'statsample'
5
16
 
6
17
  Statsample::Analysis.store(Statsample::Test::Levene) do
7
18
 
8
- a=[1,2,3,4,5,6,7,8,100,10].to_numeric
9
- b=[30,40,50,60,70,80,90,100,110,120].to_numeric
19
+ a = Daru::Vector.new([1,2,3,4,5,6,7,8,100,10])
20
+ b = Daru::Vector.new([30,40,50,60,70,80,90,100,110,120])
21
+
22
+ # The 'levene' function is used as a shorthand
23
+ # for creating a Statsample::Test::Levene object.
10
24
  summary(levene([a,b]))
11
25
  end
12
26
 
13
27
  if __FILE__==$0
14
- Statsample::Analysis.run_batch
28
+ Statsample::Analysis.run_batch
15
29
  end
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
3
 
4
+ # == Description
5
+ #
6
+ # This example shows how multiple regression can be performed using statsample and daru.
4
7
  require 'statsample'
5
8
 
6
9
  Statsample::Analysis.store(Statsample::Regression::Multiple) do
7
10
 
8
11
  samples=2000
9
- ds=dataset('a'=>rnorm(samples),'b'=>rnorm(samples),'cc'=>rnorm(samples),'d'=>rnorm(samples))
12
+ ds=dataset(:a => rnorm(samples),:b => rnorm(samples),:cc => rnorm(samples),:d => rnorm(samples))
10
13
  attach(ds)
11
- ds['y']=a*5+b*3+cc*2+d+rnorm(samples)
12
- summary lr(ds,'y')
14
+ ds[:y] = a*5+b*3+cc*2+d+rnorm(samples)
15
+ summary lr(ds,:y)
13
16
  end
14
17
 
15
18
  if __FILE__==$0
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
3
 
4
+ # == Description
5
+ #
6
+ # This example will explain how a parallel analysis can be performed on a PCA.
7
+ # Parallel Analysis helps in determining how many components are to be retained
8
+ # from the PCA.
4
9
  require 'statsample'
5
10
  samples=150
6
11
  variables=30
@@ -8,18 +13,18 @@ iterations=50
8
13
  Statsample::Analysis.store(Statsample::Factor::ParallelAnalysis) do
9
14
 
10
15
  rng = Distribution::Normal.rng()
11
- f1=rnorm(samples)
12
- f2=rnorm(samples)
13
- f3=rnorm(samples)
16
+ f1 = rnorm(samples)
17
+ f2 = rnorm(samples)
18
+ f3 = rnorm(samples)
14
19
 
15
20
  vectors={}
16
21
 
17
22
  variables.times do |i|
18
- vectors["v#{i}"]=samples.times.collect {|nv| f1[nv]*i+(f2[nv]*(15-i))+((f3[nv]*(30-i))*1.5)*rng.call}.to_numeric
19
- vectors["v#{i}"].name="Vector #{i}"
23
+ vectors["v#{i}".to_sym] = Daru::Vector.new(samples.times.collect {|nv| f1[nv]*i+(f2[nv]*(15-i))+((f3[nv]*(30-i))*1.5)*rng.call})
24
+ vectors["v#{i}".to_sym].rename "Vector #{i}"
20
25
  end
21
26
 
22
- ds=vectors.to_dataset
27
+ ds = Daru::DataFrame.new(vectors)
23
28
 
24
29
  pa=Statsample::Factor::ParallelAnalysis.new(ds, :iterations=>iterations, :debug=>true)
25
30
  pca=pca(cor(ds))
@@ -1,26 +1,39 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
- $:.unshift("/home/cdx/usr/lib/statsample-bivariate-extension/lib/")
4
3
 
4
+ # == Description
5
+ # Polychoric Correlation using two-step and joint method
6
+ #
7
+ # Polychoric correlation in statsample requires installation of
8
+ # the [statsample-bivariate-extension](https://rubygems.org/gems/statsample-bivariate-extension)
9
+ # gem. This gem extends the Statsample::Bivariate class with useful
10
+ # algorithms for polychoric and tetrachoric correlation.
11
+ #
12
+ # Statsample will automatically detect presence of polychoric/tetrachoric
13
+ # algorithms so there is no need to explicitly require the gem.
14
+ #
15
+ # In this example we'll see how polychoric correlation can be
16
+ # performed using statsample.
5
17
  require 'statsample'
6
18
  Statsample::Analysis.store(Statsample::Bivariate::Polychoric) do
7
- ct=Matrix[[rand(10)+50, rand(10)+50, rand(10)+1],
8
- [rand(20)+5, rand(50)+4, rand(10)+1],
9
- [rand(8)+1, rand(12)+1, rand(10)+1]]
19
+ ct=Matrix[[rand(10)+50, rand(10)+50, rand(10)+1],
20
+ [rand(20)+5, rand(50)+4, rand(10)+1],
21
+ [rand(8)+1, rand(12)+1, rand(10)+1]]
10
22
 
11
- # Estimation of polychoric correlation using two-step (default)
12
- poly=polychoric(ct, :name=>"Polychoric with two-step", :debug=>false)
13
- summary poly
23
+ # Estimation of polychoric correlation using two-step (default)
24
+ poly=polychoric(ct, :name=>"Polychoric with two-step", :debug=>false)
25
+ summary poly
14
26
 
15
- # Estimation of polychoric correlation using joint method (slow)
16
- poly=polychoric(ct, :method=>:joint, :name=>"Polychoric with joint")
17
- summary poly
27
+ # Estimation of polychoric correlation using joint method (slow)
28
+ poly=polychoric(ct, :method=>:joint, :name=>"Polychoric with joint")
29
+ summary poly
18
30
 
19
- # Uses polychoric series (not recomended)
31
+ # Uses polychoric series (not recomended)
20
32
 
21
- poly=polychoric(ct, :method=>:polychoric_series, :name=>"Polychoric with polychoric series")
22
- summary poly
33
+ poly=polychoric(ct, :method=>:polychoric_series, :name=>"Polychoric with polychoric series")
34
+ summary poly
23
35
  end
36
+
24
37
  if __FILE__==$0
25
38
  Statsample::Analysis.run_batch
26
39
  end
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
-
3
+ # Principal Axis Analysis¶
4
+ #
5
+ # Here we use the Statsample::Factor::PrincipalAnalysis class
6
+ # for principal axis analysis for a correlation or covariance matrix.
4
7
  require 'statsample'
5
8
 
6
9
  Statsample::Analysis.store(Statsample::Factor::PrincipalAxis) do
7
10
 
8
11
  matrix=Matrix[
9
- [1.0, 0.709501601093587, 0.877596585880047, 0.272219316266807], [0.709501601093587, 1.0, 0.291633797330304, 0.871141831433844], [0.877596585880047, 0.291633797330304, 1.0, -0.213373722977167], [0.272219316266807, 0.871141831433844, -0.213373722977167, 1.0]]
12
+ [1.0, 0.709501601093587, 0.877596585880047, 0.272219316266807],
13
+ [0.709501601093587, 1.0, 0.291633797330304, 0.871141831433844],
14
+ [0.877596585880047, 0.291633797330304, 1.0, -0.213373722977167],
15
+ [0.272219316266807, 0.871141831433844, -0.213373722977167, 1.0]]
10
16
 
11
17
  matrix.extend Statsample::CovariateMatrix
12
-
13
- #matrix.fields=%w{a b c d}
14
18
  fa=principal_axis(matrix,:m=>1,:smc=>false)
15
19
 
16
20
  summary fa
@@ -1,27 +1,28 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib')
3
- require 'statsample'
4
3
 
5
- Statsample::Analysis.store(Statsample::Reliability) do
6
-
4
+ # == Description
5
+ #
6
+ # Reliability Scale Analysis with statsample
7
+ require 'statsample'
8
+ Statsample::Analysis.store(Statsample::Reliability) do
7
9
  samples=100
8
10
  a=rnorm(samples)
9
11
 
10
- ds=Statsample::Dataset.new
12
+ ds = Daru::DataFrame.new({})
11
13
 
12
14
  20.times do |i|
13
- ds["v#{i}"]=a+rnorm(samples,0,0.2)
15
+ ds["v#{i}".to_sym]= a + rnorm(samples,0,0.2)
14
16
  end
15
17
 
16
- ds.update_valid_data
18
+ ds.update
17
19
 
18
20
  rel=Statsample::Reliability::ScaleAnalysis.new(ds)
19
21
  summary rel
20
22
 
21
-
22
23
  ms=Statsample::Reliability::MultiScaleAnalysis.new(:name=>"Multi Scale analyss") do |m|
23
- m.scale "Scale 1", ds.clone(%w{v1 v2 v3 v4 v5 v6 v7 v8 v9 v10})
24
- m.scale "Scale 2", ds.clone(%w{v11 v12 v13 v14 v15 v16 v17 v18 v19})
24
+ m.scale "Scale 1", ds.clone([:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10])
25
+ m.scale "Scale 2", ds.clone([:v11, :v12, :v13, :v14, :v15, :v16, :v17, :v18, :v19])
25
26
  end
26
27
 
27
28
  summary ms
@@ -30,4 +31,3 @@ end
30
31
  if __FILE__==$0
31
32
  Statsample::Analysis.run_batch
32
33
  end
33
-
@@ -2,6 +2,14 @@
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
3
  $:.unshift('/home/cdx/dev/reportbuilder/lib/')
4
4
 
5
+ # == Description
6
+ #
7
+ # Creating a scatterplot with statsample's Statsample::Graph::Scatterplot class.
8
+ #
9
+ # In this example we'll demonstrate how a normally distributed Daru::Vector can
10
+ # be created using the daru and distribution gems, and how the values generated
11
+ # can be plotted very easily using the 'scatterplot' shorthand and supplying X
12
+ # and Y co-ordinates.
5
13
  require 'benchmark'
6
14
  require 'statsample'
7
15
  n=100
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib')
3
+ # == Description
4
+ #
5
+ # This example illustrates how a T test can be done and summarized with statsample
6
+ #
7
+ # == References
8
+ #
9
+ # http://en.wikipedia.org/wiki/Student%27s_t-test
3
10
  require 'statsample'
4
11
 
5
12
  Statsample::Analysis.store(Statsample::Test::T) do
@@ -1,11 +1,19 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib')
3
+
4
+ # == Description
5
+ #
6
+ # Example illustrating Mann-Whitney U test with statsample.
7
+ #
8
+ # == References
9
+ #
10
+ # http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test
3
11
  require 'statsample'
4
12
 
5
13
  Statsample::Analysis.store(Statsample::Test::UMannWhitney) do
6
14
 
7
- a=10.times.map {rand(100)}.to_numeric
8
- b=20.times.map {(rand(20))**2+50}.to_numeric
15
+ a = Daru::Vector.new(10.times.map {rand(100)})
16
+ b = Daru::Vector.new(20.times.map {(rand(20))**2+50})
9
17
 
10
18
  u=Statsample::Test::UMannWhitney.new(a,b)
11
19
  summary u
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/ruby
2
2
  $:.unshift(File.dirname(__FILE__)+'/../lib/')
3
-
3
+ # == Description
4
+ #
5
+ # This example provides a small sneak-peak into creating a Daru::Vector.
6
+ # For details on using Daru::Vector (with example on math, statistics and plotting)
7
+ # see the notebook at this link:
8
+ # http://nbviewer.ipython.org/github/SciRuby/sciruby-notebooks/blob/master/Data%20Analysis/Usage%20of%20Vector.ipynb
4
9
  require 'statsample'
5
10
 
6
- Statsample::Analysis.store(Statsample::Vector) do
7
-
8
- a=Statsample::Vector.new_numeric(1000) {r=rand(5); r==4 ? nil: r;}
11
+ Statsample::Analysis.store(Daru::Vector) do
12
+ a = Daru::Vector.new_with_size(1000) {r=rand(5); r==4 ? nil: r;}
9
13
  summary a
10
- b=c(1,2,3,4,6..10)
14
+ b = Daru::Vector[1,2,3,4,6..10]
11
15
  summary b
12
-
13
16
  end
14
17
 
15
18
  if __FILE__==$0