class Statsample::GLM::IRLS::Logistic

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/logistic.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/logistic.rb, line 11
def to_s
  "Statsample::GLM::Logistic"
end

Protected Instance Methods

hessian(x, b) click to toggle source
# File lib/statsample-glm/glm/irls/logistic.rb, line 40
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/logistic.rb, line 33
def jacobian x, b, y
  mu_flat     = measurement(x,b).column_vectors.map(&:to_a).flatten
  column_data = y.zip(mu_flat).map { |x| x.inject(:-) }

  x.transpose * Matrix.column_vector(column_data)
end
measurement(x, b) click to toggle source
# File lib/statsample-glm/glm/irls/logistic.rb, line 17
def measurement x, b
  (x * b).map { |y| 1/(1 + Math.exp(-y)) }
end
weight(x, b) click to toggle source
# File lib/statsample-glm/glm/irls/logistic.rb, line 21
def weight x, b
  mus = measurement(x,b).column_vectors.map(&:to_a).flatten
  mus_intermediate = mus.map { |p| 1 - p }
  weights = mus.zip(mus_intermediate).collect { |x| x.inject(:*) }

  w_mat = Matrix.I(weights.size)
  w_enum = weights.to_enum
  return w_mat.map do |x|
    x.eql?(1) ? w_enum.next : x # diagonal consists of first derivatives of logit
  end
end