Class: Statsample::MLE::Probit
- Defined in:
- lib/statsample/mle/probit.rb
Overview
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
Constant Summary
Constants inherited from BaseMLE
BaseMLE::ITERATIONS, BaseMLE::MIN_DIFF, BaseMLE::MIN_DIFF_PARAMETERS
Instance Attribute Summary
Attributes inherited from BaseMLE
#iterations, #output, #parameters, #stop_criteria, #var_cov_matrix, #verbose
Instance Method Summary collapse
-
#f(b, x) ⇒ Object
:nodoc:.
-
#ff(b, x) ⇒ Object
:nodoc:.
-
#first_derivative(x, y, b) ⇒ Object
First derivative of log-likehood probit function x: Matrix (NxM) y: Matrix (Nx1) p: Matrix (Mx1).
-
#log_likehood_i(xi, yi, b) ⇒ Object
Log Likehood for x_i vector, y_i scalar and b parameters.
-
#second_derivative(x, y, b) ⇒ Object
Second derivative of log-likehood probit function x: Matrix (NxM) y: Matrix (Nx1) p: Matrix (Mx1).
Methods inherited from BaseMLE
#initialize, #likehood, #log_likehood, #newton_raphson, #set_default_parameters
Constructor Details
This class inherits a constructor from Statsample::MLE::BaseMLE
Instance Method Details
#f(b, x) ⇒ Object
:nodoc:
17 18 19 20 |
# 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) ⇒ Object
:nodoc:
22 23 24 25 |
# 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) ⇒ Object
First derivative of log-likehood probit function x: Matrix (NxM) y: Matrix (Nx1) p: Matrix (Mx1)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
Log Likehood for x_i vector, y_i scalar and b parameters
37 38 39 40 |
# 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) ⇒ Object
Second derivative of log-likehood probit function x: Matrix (NxM) y: Matrix (Nx1) p: Matrix (Mx1)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# 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 |