Parent

Included Modules

Class/Module Index [+]

Quicksearch

Statsample::Regression::Simple

Class for calculation of linear regressions with form

y = a+bx

To create a SimpleRegression object:

Attributes

a[RW]
b[RW]
cov00[RW]
cov01[RW]
covx1[RW]
chisq[RW]
status[RW]
name[RW]
digits[RW]

Public Class Methods

new_from_dataset(ds,x,y, opts=Hash.new) click to toggle source

Create a simple regression using a dataset and two vector names.

# File lib/statsample/regression/simple.rb, line 70
def new_from_dataset(ds,x,y, opts=Hash.new)
  new(:init_vectors,ds[x],ds[y], opts)
end
new_from_gsl(ar) click to toggle source

Create a regression object giving an array with following parameters: a,b,cov00, cov01, covx1, chisq, status Useful to obtain x and y values with a and b values.

# File lib/statsample/regression/simple.rb, line 62
def new_from_gsl(ar)
  new(:init_gsl, *ar)
end
new_from_vectors(vx,vy, opts=Hash.new) click to toggle source

Create a simple regression using two vectors

# File lib/statsample/regression/simple.rb, line 66
def new_from_vectors(vx,vy, opts=Hash.new)
  new(:init_vectors,vx,vy, opts)
end

Public Instance Methods

r() click to toggle source

Value of r

# File lib/statsample/regression/simple.rb, line 51
def r
  @b * (@vx.sds / @vy.sds)
end
r2() click to toggle source

Value of r^2

# File lib/statsample/regression/simple.rb, line 55
def r2
  r**2
end
report_building(gen) click to toggle source
# File lib/statsample/regression/simple.rb, line 106
def report_building(gen)
f="%0.#{digits}f"
  gen.section(:name=>name) do |s|
    s.table(:header=>[_("Variable"), _("Value")]) do |t|
      t.row [_("r"), f % r]
      t.row [_("r^2"), f % r2]
      t.row [_("a"), f % a]
      t.row [_("b"), f % a]
      t.row [_("s.e"), f % standard_error]
    end
  end
end
sse() click to toggle source

Sum of square error

# File lib/statsample/regression/simple.rb, line 31
def sse
  (0...@vx.size).inject(0) {|acum,i| acum+((@vy[i]-y(@vx[i]))**2)
  }
end
ssr() click to toggle source

Sum of square regression

# File lib/statsample/regression/simple.rb, line 39
def ssr
  vy_mean=@vy.mean
  (0...@vx.size).inject(0) {|a,i|
    a+((y(@vx[i])-vy_mean)**2)
  }

end
sst() click to toggle source

Sum of square total

# File lib/statsample/regression/simple.rb, line 47
def sst
  @vy.sum_of_squared_deviation
end
standard_error() click to toggle source
# File lib/statsample/regression/simple.rb, line 35
def standard_error
  Math::sqrt(sse / (@vx.size-2).to_f)
end
x(val_y) click to toggle source

Obtain x value given y value x=(y-a)/b

# File lib/statsample/regression/simple.rb, line 27
def x(val_y)
  (val_y-@a) / @b.to_f
end
y(val_x) click to toggle source

Obtain y value given x value x=a+bx

# File lib/statsample/regression/simple.rb, line 22
def y(val_x)
  @a+@b*val_x
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.