class SEstimator::Chao92

Usage SEstimator::Chao92.estimate (samples) #=> the estimation of numberof species

Public Class Methods

estimate(samples) click to toggle source
# File lib/SEstimator/chao92.rb, line 10
def self.estimate(samples)
  Chao92.new.run(samples)
end
new() click to toggle source
# File lib/SEstimator/chao92.rb, line 7
def initialize
end

Public Instance Methods

run(samples) click to toggle source
# File lib/SEstimator/chao92.rb, line 14
def run(samples)
  @samples = samples
  @ff = @samples.to_hash.to_ff
  estimate
end
show() click to toggle source

Show the samples

# File lib/SEstimator/chao92.rb, line 22
def show
  @samples
end

Private Instance Methods

estimate() click to toggle source
# File lib/SEstimator/chao92.rb, line 27
def estimate
  @turing_estimator = if @ff[1]
                        1 - @ff[1].to_f / @samples.size
                      else
                        1.0
                      end

  @n1 = @samples.uniq.size / @turing_estimator

  @cv_estimator = [@n1 * (@ff.inject(0.0) { |res, pair| res + pair.first * (pair.first - 1) * pair.last }) / @samples.size / (@samples.size - 1.0) - 1.0, 0.0].max

  @total_number = @n1 + @samples.size * (1 - @turing_estimator) / @turing_estimator * @cv_estimator
end