def slope(xx, yy, weights = nil)
      weights = Array.new(hits.length, 1) if weights.nil?

      # calculate the slope
      xx_weighted = xx.each_with_index.map { |x, i| x * weights[i] }
      yy_weighted = yy.each_with_index.map { |y, i| y * weights[i] }

      denominator = weights.reduce(0) { |a, e| a + e }

      x_mean = xx_weighted.reduce(0) { |a, e| a + e } / (denominator + 0.0)
      y_mean = yy_weighted.reduce(0) { |a, e| a + e } / (denominator + 0.0)

      numerator = (0...xx.length).reduce(0) do |a, e|
        a + (weights[e] * (xx[e] - x_mean) * (yy[e] - y_mean))
      end

      denominator = (0...xx.length).reduce(0) do |a, e|
        a + (weights[e] * ((xx[e] - x_mean)**2))
      end

      slope = numerator / (denominator + 0.0)
      y_intercept = y_mean - (slope * x_mean)

      [y_intercept, slope]
    end
def slope(xx, yy, weights = nil)
      weights = Array.new(hits.length, 1) if weights.nil?

      # calculate the slope
      xx_weighted = xx.each_with_index.map { |x, i| x * weights[i] }
      yy_weighted = yy.each_with_index.map { |y, i| y * weights[i] }

      denominator = weights.reduce(0) { |a, e| a + e }

      x_mean = xx_weighted.reduce(0) { |a, e| a + e } / (denominator + 0.0)
      y_mean = yy_weighted.reduce(0) { |a, e| a + e } / (denominator + 0.0)

      numerator = (0...xx.length).reduce(0) do |a, e|
        a + (weights[e] * (xx[e] - x_mean) * (yy[e] - y_mean))
      end

      denominator = (0...xx.length).reduce(0) do |a, e|
        a + (weights[e] * ((xx[e] - x_mean)**2))
      end

      slope = numerator / (denominator + 0.0)
      y_intercept = y_mean - (slope * x_mean)

      [y_intercept, slope]
    end
Caclulates the slope of the regression line
 give a set of 2d coordonates of the start/stop offests of the hits
 Param
 xx: +Array+ of integers
 yy : +Array+ of integers
 weights: +Array+ of integers
 Output:
 The ecuation of the regression line: [y slope]