Module: Statsample::Regression

Defined in:
lib/statsample/regression.rb,
lib/statsample/regression/simple.rb,
lib/statsample/regression/multiple.rb,
lib/statsample/regression/multiple/gslengine.rb,
lib/statsample/regression/multiple/baseengine.rb,
lib/statsample/regression/multiple/rubyengine.rb,
lib/statsample/regression/multiple/alglibengine.rb,
lib/statsample/regression/multiple/matrixengine.rb

Overview

Module for regression procedures.

Use the method on this class to generate analysis. If you need more control, you can create and control directly the objects who computes the regressions.

  • Simple Regression : Statsample::Regression::Simple

  • Multiple Regression: Statsample::Regression::Multiple

Defined Under Namespace

Modules: Multiple Classes: Simple

Constant Summary collapse

LinearDependency =
Class.new(Exception)

Class Method Summary collapse

Class Method Details

.multiple(ds, y_var, opts = Hash.new) ⇒ Object

Creates one of the Statsample::Regression::Multiple object, for OLS multiple regression. Parameters:

  • ds: Dataset.

  • y: Name of dependent variable.

  • opts: A hash with options

    • missing_data: Could be

      • :listwise: delete cases with one or more empty data (default).

      • :pairwise: uses correlation matrix. Use with caution.

Usage:

lr=Statsample::Regression::multiple(ds,:y)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/statsample/regression.rb', line 51

def self.multiple(ds,y_var, opts=Hash.new)
  missing_data= (opts[:missing_data].nil? ) ? :listwise : opts.delete(:missing_data)
  if missing_data==:pairwise
     Statsample::Regression::Multiple::RubyEngine.new(ds,y_var, opts)
  else
    if Statsample.has_gsl? and false
      Statsample::Regression::Multiple::GslEngine.new(ds, y_var, opts)
    else
      ds2=ds.reject_values(*Daru::MISSING_VALUES)
      Statsample::Regression::Multiple::RubyEngine.new(ds2,y_var, opts)
    end
  end
end

.simple(x, y) ⇒ Object

Create a Statsample::Regression::Simple object, for simple regression

  • x: independent Vector

  • y: dependent Vector

Usage:

x = Daru::Vector.new(100.times.collect {|i| rand(100)})
y = Daru::Vector.new(100.times.collect {|i| 2+x[i]*2+rand()})
sr=Statsample::Regression.simple(x,y)
sr.a
=> 2.51763295177808
sr.b
=> 1.99973746599856
sr.r
=> 0.999987881153254


35
36
37
# File 'lib/statsample/regression.rb', line 35

def self.simple(x,y)
  Statsample::Regression::Simple.new_from_vectors(x,y)
end