In Files

Class/Module Index [+]

Quicksearch

Statsample

Library for statistical analysis on Ruby


Several additions to Statsample objects, to support rserve-client

Constants

VERSION
SPLIT_TOKEN
OPTIMIZED

Public Class Methods

create_has_library(library) click to toggle source
# File lib/statsample.rb, line 120
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
load(filename) click to toggle source

Load a object saved on a file.

# File lib/statsample.rb, line 168
def load(filename)
  if File.exists? filename
    o=false
    File.open(filename,"r") {|fp| o=Marshal.load(fp) }
    o
  else
    false
  end
end
load_csv(filename, opts=Hash.new, cache=true) click to toggle source

Import an Excel file. Cache result by default

# File lib/statsample.rb, line 190
def load_csv(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=Statsample::CSV.read(filename,opts)
    ds.save(file_ds) if cache
  end
  ds
end
load_excel(filename, opts=Hash.new, cache=true) click to toggle source

Import an Excel file. Cache result by default

# File lib/statsample.rb, line 178
def load_excel(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=Statsample::Excel.read(filename)
    ds.save(file_ds) if cache
  end
  ds
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 228
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 238
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 206
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.