module Statsample

Several additions to Statsample objects, to support rserve-client

Several additions to Statsample objects, to support rserve-client

Retrieve Correlation matrix for eigth variables

Retrieve Correlation matrix for eigth variables

Constants

OPTIMIZED
SPLIT_TOKEN
VERSION

Public Class Methods

create_has_library(library) click to toggle source
# File lib/statsample.rb, line 119
def self.create_has_library(library)
  define_singleton_method("has_#{library}?") do
    cv="@@#{library}"
    if !class_variable_defined? cv
      begin 
        require library.to_s
        class_variable_set(cv,true)
      rescue LoadError
        class_variable_set(cv,false)
      end
    end
    class_variable_get(cv)
  end
end

Public Instance Methods

load(filename) click to toggle source

Load a object saved on a file.

# File lib/statsample.rb, line 166
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) click to toggle source

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

a=[1,2,3,6,7,nil,3,5].to_scale
b=[nil,nil,5,6,4,5,10,2].to_scale
c=[2,4,6,7,4,5,6,7].to_scale
a2,b2,c2=Statsample.only_valid(a,b,c)
=> [#<Statsample::Scale:0xb748c8c8 @data=[3, 6, 7, 3, 5]>, 
      #<Statsample::Scale:0xb748c814 @data=[5, 6, 4, 10, 2]>, 
      #<Statsample::Scale:0xb748c760 @data=[6, 7, 4, 6, 7]>]
# File lib/statsample.rb, line 204
def only_valid(*vs)
  i=1
  h=vs.inject({}) {|a,v| a["v#{i}"]=v;i+=1;a}
  ds=Statsample::Dataset.new(h).dup_only_valid
  ds.vectors.values
end
only_valid_clone(*vs) click to toggle source

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

# File lib/statsample.rb, line 214
def only_valid_clone(*vs)
  if vs.any? {|v| v.flawed?}
    only_valid(*vs)
  else
    vs
  end
end
vector_cols_matrix(*vs) click to toggle source

Create a matrix using vectors as columns. Use:

matrix=Statsample.vector_cols_matrix(v1,v2)
# File lib/statsample.rb, line 182
def vector_cols_matrix(*vs)
  # test
  size=vs[0].size
  vs.each{|v|
    raise ArgumentError,"Arguments should be Vector" unless v.instance_of? Statsample::Vector
    raise ArgumentError,"Vectors size should be the same" if v.size!=size
  }
  Matrix.rows((0...size).to_a.collect() {|i|
    vs.collect{|v| v[i]}
  })
end