Module: Statsample::Regression::Multiple

Defined in:
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 OLS Multiple Regression Analysis.

Use:.

require 'statsample'
a = Daru::Vector.new(1000.times.collect {rand})
b = Daru::Vector.new(1000.times.collect {rand})
c = Daru::Vector.new(1000.times.collect {rand})
ds= Daru::DataFrame.new({:a => a,:b => b,:c => c})
ds[:y]=ds.collect{|row| row[:a]*5 + row[:b]*3 + row[:c]*2 + rand()}
lr=Statsample::Regression.multiple(ds, :y)
puts lr.summary
Summary for regression of a,b,c over y
*************************************************************
Engine: Statsample::Regression::Multiple::AlglibEngine
Cases(listwise)=1000(1000)
r=0.986
r2=0.973
Equation=0.504+5.011a + 2.995b + 1.988c
----------------------------
ANOVA TABLE
--------------------------------------------------------------
|  source     | ss       | df  | ms      | f         | s     |
--------------------------------------------------------------
|  Regression | 2979.321 | 3   | 993.107 | 12040.067 | 0.000 |
|  Error      | 82.154   | 996 | 0.082   |           |       |
|  Total      | 3061.475 | 999 |         |           |       |
--------------------------------------------------------------
Beta coefficientes
-----------------------------------------------
|  coeff    | b     | beta  | se    | t       |
-----------------------------------------------
|  Constant | 0.504 | -     | 0.030 | 16.968  |
|  a        | 5.011 | 0.832 | 0.031 | 159.486 |
|  b        | 2.995 | 0.492 | 0.032 | 94.367  |
|  c        | 1.988 | 0.323 | 0.032 | 62.132  |
-----------------------------------------------

Defined Under Namespace

Classes: AlglibEngine, BaseEngine, GslEngine, MatrixEngine, MultipleDependent, RubyEngine

Class Method Summary collapse

Class Method Details

.r2_from_matrices(rxx, rxy) ⇒ Object

Obtain r2 for regressors



44
45
46
47
# File 'lib/statsample/regression/multiple.rb', line 44

def self.r2_from_matrices(rxx,rxy)
  matrix=(rxy.transpose*rxx.inverse*rxy)
  matrix[0,0]
end