lib/linefit.rb
############################################################################
# Return the variances in the estiamtes of the intercept and slope
#
#  varianceIntercept, varianceSlope = linefit.varianceOfEstimates
#
# Assuming the data are noisy or inaccurate, the intercept and slope
# returned by the coefficients() method are only estimates of the true
# intercept and slope. The varianceofEstimate() method returns the
# variances of the estimates of the intercept and slope, respectively. See
# Numerical Recipes in C, section 15.2 (Fitting Data to a Straight Line),
# equation 15.2.9.
#
# The returned list is undefined if the regression fails. If weights are
# input, the returned values are the weighted variances.
#
Return the variances in the estiamtes of the intercept and slope
varianceIntercept, varianceSlope = linefit.varianceOfEstimates

Assuming the data are noisy or inaccurate, the intercept and slope
returned by the coefficients() method are only estimates of the true
intercept and slope. The varianceofEstimate() method returns the
variances of the estimates of the intercept and slope, respectively. See
Numerical Recipes in C, section 15.2 (Fitting Data to a Straight Line),
equation 15.2.9.

The returned list is undefined if the regression fails. If weights are
input, the returned values are the weighted variances.
Return the variances in the estiamtes of the intercept and slope varianceIntercept varianceSlope = linefit . varianceOfEstimates Assuming the data are noisy or inaccurate the intercept and slope returned by the coefficients () method are only estimates of the true intercept and slope . The varianceofEstimate () method returns the variances of the estimates of the intercept and slope respectively . See Numerical Recipes in C section 15 . 2 ( Fitting Data to a Straight Line ) equation 15 . 2 . 9 . The returned list is undefined if the regression fails . If weights are input the returned values are the weighted variances .
def varianceOfEstimates
      unless @intercept and @slope
         self.regress or return
      end
      predictedYs = predictedYs()
      s = sx = sxx = 0
      if @weight
         0.upto(@numxy-1) do |i|
            variance = (predictedYs[i] - @y[i]) ** 2
            unless variance == 0
               s   += 1.0 / variance
               sx  += @weight[i] * @x[i] / variance
               sxx += @weight[i] * @x[i] ** 2 / variance
            end
         end
      else
         0.upto(@numxy-1) do |i|
            variance = (predictedYs[i] - @y[i]) ** 2
            unless variance == 0
               s   += 1.0 / variance
               sx  += @x[i] / variance
               sxx += @x[i] ** 2 / variance
            end
         end
      end
      denominator = (s * sxx - sx ** 2)
      if denominator == 0
         return
      else
         return sxx / denominator, s / denominator
      end
   end
def varianceOfEstimates unless @intercept and @slope self . regress or return end predictedYs = predictedYs ( ) s = sx = sxx = 0 if @weight 0 . upto ( @numxy - 1 ) do | i | variance = ( predictedYs [ i ] - @y [ i ] ) ** 2 unless variance == 0 s += 1.0 / variance sx += @weight [ i ] * @x [ i ] / variance sxx += @weight [ i ] * @x [ i ] ** 2 / variance end end else 0 . upto ( @numxy - 1 ) do | i | variance = ( predictedYs [ i ] - @y [ i ] ) ** 2 unless variance == 0 s += 1.0 / variance sx += @x [ i ] / variance sxx += @x [ i ] ** 2 / variance end end end denominator = ( s * sxx - sx ** 2 ) if denominator == 0 return else return sxx / denominator , s / denominator end end
Return the variances in the estiamtes of the intercept and slope
varianceIntercept, varianceSlope = linefit.varianceOfEstimates
Return the variances in the estiamtes of the intercept and slope varianceIntercept varianceSlope = linefit . varianceOfEstimates