statsample 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.build.sh +15 -0
- data/.gitignore +1 -0
- data/.travis.yml +19 -7
- data/CONTRIBUTING.md +33 -0
- data/History.txt +5 -0
- data/README.md +41 -53
- data/benchmarks/correlation_matrix_15_variables.rb +6 -5
- data/benchmarks/correlation_matrix_5_variables.rb +6 -5
- data/benchmarks/correlation_matrix_methods/correlation_matrix.rb +23 -26
- data/examples/boxplot.rb +17 -5
- data/examples/correlation_matrix.rb +36 -7
- data/examples/dataset.rb +25 -5
- data/examples/dominance_analysis.rb +8 -7
- data/examples/dominance_analysis_bootstrap.rb +16 -11
- data/examples/histogram.rb +16 -2
- data/examples/icc.rb +5 -6
- data/examples/levene.rb +17 -3
- data/examples/multiple_regression.rb +6 -3
- data/examples/parallel_analysis.rb +11 -6
- data/examples/polychoric.rb +26 -13
- data/examples/principal_axis.rb +8 -4
- data/examples/reliability.rb +10 -10
- data/examples/scatterplot.rb +8 -0
- data/examples/t_test.rb +7 -0
- data/examples/u_test.rb +10 -2
- data/examples/vector.rb +9 -6
- data/examples/velicer_map_test.rb +12 -8
- data/lib/statsample.rb +13 -47
- data/lib/statsample/analysis/suite.rb +1 -1
- data/lib/statsample/anova/oneway.rb +6 -6
- data/lib/statsample/anova/twoway.rb +26 -24
- data/lib/statsample/bivariate.rb +78 -61
- data/lib/statsample/bivariate/pearson.rb +2 -2
- data/lib/statsample/codification.rb +45 -32
- data/lib/statsample/converter/csv.rb +15 -53
- data/lib/statsample/converter/spss.rb +6 -5
- data/lib/statsample/converters.rb +50 -211
- data/lib/statsample/crosstab.rb +26 -25
- data/lib/statsample/daru.rb +117 -0
- data/lib/statsample/dataset.rb +70 -942
- data/lib/statsample/dominanceanalysis.rb +16 -17
- data/lib/statsample/dominanceanalysis/bootstrap.rb +26 -28
- data/lib/statsample/factor/parallelanalysis.rb +17 -19
- data/lib/statsample/factor/pca.rb +21 -20
- data/lib/statsample/factor/principalaxis.rb +3 -3
- data/lib/statsample/graph/boxplot.rb +8 -16
- data/lib/statsample/graph/histogram.rb +4 -4
- data/lib/statsample/graph/scatterplot.rb +8 -7
- data/lib/statsample/histogram.rb +128 -119
- data/lib/statsample/matrix.rb +20 -16
- data/lib/statsample/multiset.rb +39 -38
- data/lib/statsample/regression.rb +3 -3
- data/lib/statsample/regression/multiple.rb +8 -10
- data/lib/statsample/regression/multiple/alglibengine.rb +96 -89
- data/lib/statsample/regression/multiple/baseengine.rb +32 -32
- data/lib/statsample/regression/multiple/gslengine.rb +33 -36
- data/lib/statsample/regression/multiple/matrixengine.rb +7 -9
- data/lib/statsample/regression/multiple/rubyengine.rb +39 -41
- data/lib/statsample/reliability.rb +23 -25
- data/lib/statsample/reliability/icc.rb +8 -7
- data/lib/statsample/reliability/multiscaleanalysis.rb +14 -12
- data/lib/statsample/reliability/scaleanalysis.rb +58 -60
- data/lib/statsample/reliability/skillscaleanalysis.rb +34 -29
- data/lib/statsample/resample.rb +1 -1
- data/lib/statsample/shorthand.rb +29 -25
- data/lib/statsample/test/kolmogorovsmirnov.rb +5 -3
- data/lib/statsample/test/levene.rb +28 -27
- data/lib/statsample/test/t.rb +7 -9
- data/lib/statsample/test/umannwhitney.rb +28 -28
- data/lib/statsample/test/wilcoxonsignedrank.rb +45 -43
- data/lib/statsample/vector.rb +70 -1013
- data/lib/statsample/version.rb +1 -1
- data/statsample.gemspec +12 -16
- data/test/helpers_tests.rb +1 -1
- data/test/test_analysis.rb +17 -17
- data/test/test_anova_contrast.rb +6 -6
- data/test/test_anovatwowaywithdataset.rb +8 -8
- data/test/test_anovawithvectors.rb +8 -8
- data/test/test_awesome_print_bug.rb +1 -1
- data/test/test_bartlettsphericity.rb +4 -4
- data/test/test_bivariate.rb +48 -43
- data/test/test_codification.rb +33 -33
- data/test/test_crosstab.rb +9 -9
- data/test/test_dataset.rb +28 -458
- data/test/test_factor.rb +46 -38
- data/test/test_factor_pa.rb +22 -13
- data/test/test_ggobi.rb +4 -4
- data/test/test_gsl.rb +4 -4
- data/test/test_histogram.rb +3 -3
- data/test/test_matrix.rb +13 -13
- data/test/test_multiset.rb +103 -91
- data/test/test_regression.rb +57 -52
- data/test/test_reliability.rb +55 -45
- data/test/test_reliability_icc.rb +8 -8
- data/test/test_reliability_skillscale.rb +26 -24
- data/test/test_resample.rb +1 -1
- data/test/test_statistics.rb +3 -13
- data/test/test_stest.rb +9 -9
- data/test/test_stratified.rb +3 -3
- data/test/test_test_t.rb +12 -12
- data/test/test_umannwhitney.rb +2 -2
- data/test/test_vector.rb +76 -613
- data/test/test_wilcoxonsignedrank.rb +4 -4
- metadata +57 -28
- data/lib/statsample/rserve_extension.rb +0 -20
- data/lib/statsample/vector/gsl.rb +0 -106
- data/test/fixtures/repeated_fields.csv +0 -7
- data/test/fixtures/scientific_notation.csv +0 -4
- data/test/fixtures/test_csv.csv +0 -7
- data/test/fixtures/test_xls.xls +0 -0
- data/test/test_csv.rb +0 -63
- data/test/test_rserve_extension.rb +0 -42
- data/test/test_xls.rb +0 -52
data/examples/dataset.rb
CHANGED
@@ -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(
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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={
|
15
|
+
ds = Daru::DataFrame.new({:a => a,:b => b,:cc => c,:d => d}, clone: false)
|
15
16
|
attach(ds)
|
16
|
-
ds[
|
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
|
20
|
+
lr=lr(ds,:y)
|
20
21
|
summary(lr)
|
21
|
-
da=dominance_analysis(ds
|
22
|
+
da=dominance_analysis(ds,:y)
|
22
23
|
summary(da)
|
23
24
|
|
24
|
-
da=dominance_analysis(ds
|
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.
|
13
|
-
b.
|
14
|
-
c.
|
15
|
-
d.
|
15
|
+
a.rename :a
|
16
|
+
b.rename :b
|
17
|
+
c.rename :c
|
18
|
+
d.rename :d
|
16
19
|
|
17
|
-
ds={
|
20
|
+
ds = Daru::DataFrame.new({:a => a,:b => b,:cc => c,:d => d})
|
18
21
|
attach(ds)
|
19
|
-
ds[
|
20
|
-
ds[
|
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, [
|
25
|
+
dab=dominance_analysis_bootstrap(ds, [:y1,:y2], :debug=>true)
|
23
26
|
dab.bootstrap(100,nil)
|
24
27
|
summary(dab)
|
25
|
-
ds2=ds[
|
26
|
-
dab2=dominance_analysis_bootstrap(ds2,
|
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
|
data/examples/histogram.rb
CHANGED
@@ -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
|
data/examples/icc.rb
CHANGED
@@ -6,18 +6,17 @@ require 'statsample'
|
|
6
6
|
Statsample::Analysis.store(Statsample::Reliability::ICC) do
|
7
7
|
|
8
8
|
size=1000
|
9
|
-
a=
|
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={
|
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
|
data/examples/levene.rb
CHANGED
@@ -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]
|
9
|
-
b=[30,40,50,60,70,80,90,100,110,120]
|
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
|
-
|
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(
|
12
|
+
ds=dataset(:a => rnorm(samples),:b => rnorm(samples),:cc => rnorm(samples),:d => rnorm(samples))
|
10
13
|
attach(ds)
|
11
|
-
ds[
|
12
|
-
summary lr(ds
|
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}
|
19
|
-
vectors["v#{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
|
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))
|
data/examples/polychoric.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
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
|
data/examples/principal_axis.rb
CHANGED
@@ -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],
|
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
|
data/examples/reliability.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
$:.unshift(File.dirname(__FILE__)+'/../lib')
|
3
|
-
require 'statsample'
|
4
3
|
|
5
|
-
|
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=
|
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.
|
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(
|
24
|
-
m.scale "Scale 2", ds.clone(
|
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
|
-
|
data/examples/scatterplot.rb
CHANGED
@@ -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
|
data/examples/t_test.rb
CHANGED
@@ -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
|
data/examples/u_test.rb
CHANGED
@@ -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)}
|
8
|
-
b=20.times.map {(rand(20))**2+50}
|
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
|
data/examples/vector.rb
CHANGED
@@ -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(
|
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=
|
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
|