Parent

Class/Module Index [+]

Quicksearch

Statsample::MLE::Probit

Probit MLE estimation. See Statsample::Regression for methods to generate a probit regression.

Usage:

mle=Statsample::MLE::Probit.new
mle.newton_raphson(x,y)
beta=mle.parameters
likehood=mle.likehood(x,y,beta)
iterations=mle.iterations

Public Instance Methods

f(b,x) click to toggle source

F(B’Xi)

# File lib/statsample/mle/probit.rb, line 17
def f(b,x)
    p_bx=(x*b)[0,0] 
    GSL::Cdf::ugaussian_P(p_bx)
end
ff(b,x) click to toggle source

f(B’Xi)

# File lib/statsample/mle/probit.rb, line 22
def ff(b,x)
    p_bx=(x*b)[0,0] 
    GSL::Ran::ugaussian_pdf(p_bx)
end
first_derivative(x,y,b) click to toggle source

First derivative of log-likehood probit function x: Matrix (NxM) y: Matrix (Nx1) p: Matrix (Mx1)

# File lib/statsample/mle/probit.rb, line 45
def first_derivative(x,y,b)
  raise "x.rows!=y.rows" if x.row_size!=y.row_size
  raise "x.columns!=p.rows" if x.column_size!=b.row_size            
  n = x.row_size
  k = x.column_size
  fd = Array.new(k)
  k.times {|i| fd[i] = [0.0]}
  n.times do |i|
    xi = Matrix.rows([x.row(i).to_a])
    fbx=f(b,xi)
    value1 = (y[i,0]-fbx)/ ( fbx*(1-fbx))*ff(b,xi) 
    k.times do |j|
      fd[j][0] += value1*xi[0,j]
    end
  end
  Matrix.rows(fd, true)
end
log_likehood_i(xi,yi,b) click to toggle source

Log Likehood for x_i vector, y_i scalar and b parameters

# File lib/statsample/mle/probit.rb, line 37
def log_likehood_i(xi,yi,b)
  fbx=f(b,xi)
  (yi.to_f*Math::log(fbx))+((1.0-yi.to_f)*Math::log(1.0-fbx))
end
second_derivative(x,y,b) click to toggle source

Second derivative of log-likehood probit function x: Matrix (NxM) y: Matrix (Nx1) p: Matrix (Mx1)

# File lib/statsample/mle/probit.rb, line 67
def second_derivative(x,y,b)
  raise "x.rows!=y.rows" if x.row_size!=y.row_size
  raise "x.columns!=p.rows" if x.column_size!=b.row_size
  n = x.row_size
  k = x.column_size
  if Statsample.has_gsl?
    sum=GSL::Matrix.zeros(k)
  else
    sum=Matrix.zero(k)
  end
  n.times do |i|
    xi=Matrix.rows([x.row(i).to_a])
    fbx=f(b,xi)
    val=((ff(b,xi)**2) / (fbx*(1.0-fbx)))*xi.t*xi
    if Statsample.has_gsl?
      val=val.to_gsl
    end
    sum-=val
  end
  if Statsample.has_gsl?
    sum=sum.to_matrix
  end
  sum
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.