lib/statsample/bivariate/polychoric.rb in statsample-0.6.3 vs lib/statsample/bivariate/polychoric.rb in statsample-0.6.4
- old
+ new
@@ -46,37 +46,39 @@
attr_accessor :name
# Max number of iterations used on iterative methods. Default to MAX_ITERATIONS
attr_accessor :max_iterations
# Debug algorithm (See iterations, for example)
attr_accessor :debug
- # Minimizer type. Default GSL::Min::FMinimizer::BRENT
+ # Minimizer type for two step. Default "brent"
# See http://rb-gsl.rubyforge.org/min.html for reference.
attr_accessor :minimizer_type_two_step
- # Minimizer type. Default GSL::Min::FMinimizer::BRENT
+ # Minimizer type for joint estimate. Default "nmsimplex"
# See http://rb-gsl.rubyforge.org/min.html for reference.
attr_accessor :minimizer_type_joint
# Method of calculation of polychoric series.
#
- # :two_step:: two-step ML, based on code by Gegenfurtner(1992)
+ # :two_step:: two-step ML, based on code by Gegenfurtner(1992).
# :polychoric_series:: polychoric series estimate, using
- # algorithm AS87 by Martinson and Hamdan (1975)
- # :joint: one-step ML, based on R package 'polycor'
+ # algorithm AS87 by Martinson and Hamdan (1975).
+ # :joint:: one-step ML, based on R package 'polycor'
# by J.Fox.
attr_accessor :method
# Absolute error for iteration.
attr_accessor :epsilon
# Number of iterations
attr_reader :iteration
# Log of algorithm
attr_reader :log
- attr_reader :loglike
+
+ attr_reader :loglike_model
+
METHOD=:two_step
MAX_ITERATIONS=300
EPSILON=0.000001
MINIMIZER_TYPE_TWO_STEP="brent"
MINIMIZER_TYPE_JOINT="nmsimplex"
@@ -160,20 +162,19 @@
end
end
def loglike_data
loglike=0
- @nr.times { |i|
- @nc.times { |j|
+ @nr.times do |i|
+ @nc.times do |j|
res=@matrix[i,j].quo(@total)
if (res==0)
- # puts "Correccion"
- res=1e-16
- end
+ res=1e-16
+ end
loglike+= @matrix[i,j] * Math::log(res )
- }
- }
+ end
+ end
loglike
end
def chi_square
if @loglike_model.nil?
compute
@@ -344,10 +345,10 @@
for i in 0...np do
message+=sprintf("%10.3e ", x[i])
end
message+=sprintf("f() = %7.3f size = %.3f\n", minimizer.fval, minimizer.size)+"\n";
end while status == GSL::CONTINUE and iter < @max_iterations
- @iteration=@iter
+ @iteration=iter
@log+=message
puts message if @debug
@r=minimizer.x[0]
@alpha=minimizer.x[1,@nr-1].to_a
@beta=minimizer.x[@nr,@nc-1].to_a