Module: Statsample::Shorthand

Included in:
Analysis::Suite
Defined in:
lib/statsample/shorthand.rb

Overview

Module which provide shorthands for many methods.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rnorm(n, mean = 0, sd = 1) ⇒ Object

Random generation for the normal distribution



53
54
55
56
# File 'lib/statsample/shorthand.rb', line 53

def rnorm(n,mean=0,sd=1)
  rng=Distribution::Normal.rng(mean,sd)
  Statsample::Vector.new_numeric(n) { rng.call}
end

.test_u(*args) ⇒ Object



116
117
118
# File 'lib/statsample/shorthand.rb', line 116

def test_u(*args)
  Statsample::Test::UMannWhitney.new(*args)
end

Instance Method Details

#boxplot(*args) ⇒ Object

Returns a Statsample::Graph::Boxplot



65
66
67
# File 'lib/statsample/shorthand.rb', line 65

def boxplot(*args)
  Statsample::Graph::Boxplot.new(*args)
end

#cor(ds) ⇒ Object

Create a correlation matrix from a dataset



40
41
42
# File 'lib/statsample/shorthand.rb', line 40

def cor(ds)
  Statsample::Bivariate.correlation_matrix(ds)
end

#cov(ds) ⇒ Object

Create a variance/covariance matrix from a dataset



44
45
46
# File 'lib/statsample/shorthand.rb', line 44

def cov(ds)
  Statsample::Bivariate.covariate_matrix(ds)
end

#dataset(vectors = Hash.new) ⇒ Object Also known as: data_frame

Creates a new Statsample::Dataset Each key is transformed into string



59
60
61
62
# File 'lib/statsample/shorthand.rb', line 59

def dataset(vectors=Hash.new)
  vectors=vectors.inject({}) {|ac,v| ac[v[0].to_s]=v[1];ac}
  Statsample::Dataset.new(vectors)
end

#dominance_analysis(*args) ⇒ Object



101
102
103
# File 'lib/statsample/shorthand.rb', line 101

def dominance_analysis(*args)
  Statsample::DominanceAnalysis.new(*args)
end

#dominance_analysis_bootstrap(*args) ⇒ Object



104
105
106
# File 'lib/statsample/shorthand.rb', line 104

def dominance_analysis_bootstrap(*args)
  Statsample::DominanceAnalysis::Bootstrap.new(*args)
end

#histogram(*args) ⇒ Object

Returns a Statsample::Graph::Histogram



69
70
71
# File 'lib/statsample/shorthand.rb', line 69

def histogram(*args)
  Statsample::Graph::Histogram.new(*args)
end

#levene(*args) ⇒ Object

Returns a Statsample::Test::Levene



78
79
80
# File 'lib/statsample/shorthand.rb', line 78

def levene(*args)
  Statsample::Test::Levene.new(*args)
end

#lr(*args) ⇒ Object

Other Shortcuts



95
96
97
# File 'lib/statsample/shorthand.rb', line 95

def lr(*args)
  Statsample::Regression.multiple(*args)
end

#multiscale_analysis(*args, &block) ⇒ Object



113
114
115
# File 'lib/statsample/shorthand.rb', line 113

def multiscale_analysis(*args,&block)
  Statsample::Reliability::MultiScaleAnalysis.new(*args,&block)
end

#names(ds) ⇒ Object

Retrieve names (fields) from dataset



36
37
38
# File 'lib/statsample/shorthand.rb', line 36

def names(ds)
  ds.fields
end

#pca(ds, opts = Hash.new) ⇒ Object



98
99
100
# File 'lib/statsample/shorthand.rb', line 98

def pca(ds,opts=Hash.new)
  Statsample::Factor::PCA.new(ds,opts)
end

#polychoric(*args) ⇒ Object



85
86
87
# File 'lib/statsample/shorthand.rb', line 85

def polychoric(*args)
  Statsample::Bivariate::Polychoric.new(*args)
end

#principal_axis(*args) ⇒ Object



81
82
83
84
# File 'lib/statsample/shorthand.rb', line 81

def principal_axis(*args)
  Statsample::Factor::PrincipalAxis.new(*args)
  
end

#read_csvObject

Import an CSV file. Cache result by default



31
32
33
# File 'lib/statsample/shorthand.rb', line 31

def read_csv
  read_with_cache(Statsample::CSV, filename, opts, cache)
end

#read_excel(filename, opts = Hash.new, cache = true) ⇒ Object

Import an Excel file. Cache result by default



25
26
27
28
# File 'lib/statsample/shorthand.rb', line 25

def read_excel(filename, opts=Hash.new, cache=true)
  read_with_cache(Statsample::Excel, filename, opts, cache)

end

#read_with_cache(klass, filename, opts = Hash.new, cache = true) ⇒ Object

:section: R like methods



14
15
16
17
18
19
20
21
22
23
# File 'lib/statsample/shorthand.rb', line 14

def read_with_cache(klass, filename,opts=Hash.new, cache=true)
  file_ds=filename+".ds"
  if cache and (File.exists? file_ds and File.mtime(file_ds)>File.mtime(filename))
    ds=Statsample.load(file_ds)
  else
    ds=klass.read(filename)
    ds.save(file_ds) if cache
  end
  ds
end

#scale_analysis(*args) ⇒ Object



107
108
109
# File 'lib/statsample/shorthand.rb', line 107

def scale_analysis(*args)
  Statsample::Reliability::ScaleAnalysis.new(*args)
end

#scatterplot(*args) ⇒ Object

Returns a Statsample::Graph::Scatterplot



74
75
76
# File 'lib/statsample/shorthand.rb', line 74

def scatterplot(*args)
  Statsample::Graph::Scatterplot.new(*args)
end

#skill_scale_analysis(*args) ⇒ Object



110
111
112
# File 'lib/statsample/shorthand.rb', line 110

def skill_scale_analysis(*args)
  Statsample::Reliability::SkillScaleAnalysis.new(*args)
end

#tetrachoric(*args) ⇒ Object



88
89
90
# File 'lib/statsample/shorthand.rb', line 88

def tetrachoric(*args)
  Statsample::Bivariate::Tetrachoric.new(*args)
end

#vector(*args) ⇒ Object

Create a Statsample::Vector Analog to R’s c



49
50
51
# File 'lib/statsample/shorthand.rb', line 49

def vector(*args)
  Statsample::Vector[*args]
end