class Statsample::GLM::IRLS::Poisson

Public Class Methods

new(data_set, dependent, opts={}) click to toggle source
Calls superclass method Statsample::GLM::IRLS::Base::new
# File lib/statsample-glm/glm/irls/poisson.rb, line 7
def initialize data_set, dependent, opts={}
  super data_set, dependent, opts
end

Public Instance Methods

to_s() click to toggle source
# File lib/statsample-glm/glm/irls/poisson.rb, line 11
def to_s
  puts "Logistic Regression (Statsample::Regression::GLM::Logistic)"
end

Protected Instance Methods

hessian(x, b) click to toggle source
# File lib/statsample-glm/glm/irls/poisson.rb, line 35
def hessian x, b
  (x.transpose * weight(x, b) * x).map { |x| -x }
end
jacobian(x, b, y) click to toggle source
# File lib/statsample-glm/glm/irls/poisson.rb, line 39
def jacobian x, b, y
  measurement_flat = measurement(x,b).column_vectors.map(&:to_a).flatten
  column_data = y.zip(measurement_flat).collect { |x| x.inject(:-) }

  x.transpose * Matrix.columns([column_data])
end
measurement(x, b) click to toggle source
# File lib/statsample-glm/glm/irls/poisson.rb, line 16
def measurement x, b
  if @opts[:link] == :log
    (x * b).map { |y| Math.exp(y) }
  elsif @opts[:link] == :sqrt
    (x * b).map { |y| y**2 }
  end
end
weight(x, b) click to toggle source
# File lib/statsample-glm/glm/irls/poisson.rb, line 24
def weight x, b
  m = measurement(x,b).column_vectors.map(&:to_a).flatten

  w_mat  = Matrix.I(m.size)
  w_enum = m.to_enum

  return w_mat.map do |x|
    x.eql?(1) ? w_enum.next : x # diagonal consists of first derivatives of logit
  end
end