Module: Statsample

Defined in:
lib/statsample.rb,
lib/statsample/srs.rb,
lib/statsample/test.rb,
lib/statsample/anova.rb,
lib/statsample/graph.rb,
lib/statsample/matrix.rb,
lib/statsample/factor.rb,
lib/statsample/test/t.rb,
lib/statsample/test/f.rb,
lib/statsample/version.rb,
lib/statsample/analysis.rb,
lib/statsample/multiset.rb,
lib/statsample/resample.rb,
lib/statsample/crosstab.rb,
lib/statsample/histogram.rb,
lib/statsample/bivariate.rb,
lib/statsample/shorthand.rb,
lib/statsample/factor/map.rb,
lib/statsample/factor/pca.rb,
lib/statsample/regression.rb,
lib/statsample/converters.rb,
lib/statsample/reliability.rb,
lib/statsample/test/levene.rb,
lib/statsample/anova/oneway.rb,
lib/statsample/anova/twoway.rb,
lib/statsample/codification.rb,
lib/statsample/graph/boxplot.rb,
lib/statsample/converter/csv.rb,
lib/statsample/converter/spss.rb,
lib/statsample/analysis/suite.rb,
lib/statsample/anova/contrast.rb,
lib/statsample/test/chisquare.rb,
lib/statsample/graph/histogram.rb,
lib/statsample/reliability/icc.rb,
lib/statsample/factor/rotation.rb,
lib/statsample/dominanceanalysis.rb,
lib/statsample/graph/scatterplot.rb,
lib/statsample/regression/simple.rb,
lib/statsample/bivariate/pearson.rb,
lib/statsample/test/umannwhitney.rb,
lib/statsample/regression/multiple.rb,
lib/statsample/factor/principalaxis.rb,
lib/statsample/test/kolmogorovsmirnov.rb,
lib/statsample/factor/parallelanalysis.rb,
lib/statsample/test/wilcoxonsignedrank.rb,
lib/statsample/test/bartlettsphericity.rb,
lib/statsample/reliability/scaleanalysis.rb,
lib/statsample/dominanceanalysis/bootstrap.rb,
lib/statsample/analysis/suitereportbuilder.rb,
lib/statsample/regression/multiple/gslengine.rb,
lib/statsample/reliability/skillscaleanalysis.rb,
lib/statsample/reliability/multiscaleanalysis.rb,
lib/statsample/regression/multiple/rubyengine.rb,
lib/statsample/regression/multiple/baseengine.rb,
lib/statsample/regression/multiple/matrixengine.rb,
lib/statsample/regression/multiple/alglibengine.rb

Overview

This module will be removed in the next release. Please shift to using Daru::DataFrame.from_csv and #write_csv for CSV related operations.

Defined Under Namespace

Modules: Analysis, Anova, Bivariate, Codification, CovariateMatrix, Database, Factor, GGobi, Graph, Mondrian, Mx, NamedMatrix, Regression, Reliability, Resample, SPSS, SRS, STATSAMPLE__, Shorthand, Summarizable, Test, Util, VectorShorthands, Writable Classes: CSV, Crosstab, DominanceAnalysis, Excel, Histogram, Multiset, PlainText, StratifiedSample

Constant Summary

SPLIT_TOKEN =
','
VERSION =
'2.0.2'

Class Method Summary collapse

Class Method Details

.create_has_library(library) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/statsample.rb', line 122

def self.create_has_library(library)
  define_singleton_method("has_#{library}?") do
    cv = "@@#{library}"
    unless class_variable_defined? cv
      begin
        gem library.to_s # activate gem
        require library.to_s
        class_variable_set(cv, true)
      rescue LoadError
        class_variable_set(cv, false)
      end
    end
    class_variable_get(cv)
  end
end

.load(filename) ⇒ Object

Load a object saved on a file.



169
170
171
172
173
174
175
176
177
# File 'lib/statsample.rb', line 169

def load(filename)
  if File.exist? filename
    o = false
    File.open(filename, 'r') { |fp| o = Marshal.load(fp) }
    o
  else
    false
  end
end

.only_valid(*vs) ⇒ Object

Returns a duplicate of the input vectors, without missing data for any of the vectors.

a = Daru::Vector.new([1,2,3,6,7,nil,3,5])
b = Daru::Vector.new([nil,nil,5,6,4,5,10,2])
c = Daru::Vector.new([2,4,6,7,4,5,6,7])
a2,b2,c2=Statsample.only_valid(a,b,c)
=> [#<Daru::Vector:0xb748c8c8 @data=[3, 6, 7, 3, 5]>,
      #<Daru::Vector:0xb748c814 @data=[5, 6, 4, 10, 2]>,
      #<Daru::Vector:0xb748c760 @data=[6, 7, 4, 6, 7]>]


206
207
208
209
210
211
# File 'lib/statsample.rb', line 206

def only_valid(*vs)
  i = 1
  h = vs.inject({}) { |acc, v| acc["v#{i}".to_sym] = v; i += 1; acc }
  df = Daru::DataFrame.new(h).dup_only_valid
  df.map { |v| v }
end

.only_valid_clone(*vs) ⇒ Object

Cheap version of #only_valid. If any vectors have missing_values, return only valid. If not, return the vectors itself



216
217
218
219
220
221
222
# File 'lib/statsample.rb', line 216

def only_valid_clone(*vs)
  if vs.any?(&:has_missing_data?)
    only_valid(*vs)
  else
    vs
  end
end

.vector_cols_matrix(*vs) ⇒ Object

Create a matrix using vectors as columns. Use:

matrix=Statsample.vector_cols_matrix(v1,v2)


183
184
185
186
187
188
189
190
191
192
193
# File 'lib/statsample.rb', line 183

def vector_cols_matrix(*vs)
  # test
  size = vs[0].size

  vs.each do |v|
    fail ArgumentError, 'Arguments should be Vector' unless v.instance_of? Daru::Vector
    fail ArgumentError, 'Vectors size should be the same' if v.size != size
  end

  Matrix.rows((0...size).to_a.collect { |i| vs.collect { |v| v[i] } })
end