lib/linefit.rb
############################################################################
# Do the least squares line fit (if not already done)
#
#  linefit.regress
#
# You don't need to call this method because it is invoked by the other
# methods as needed. After you call setData(), you can call regress() at
# any time to get the status of the regression for the current data.
#
Do the least squares line fit (if not already done)
linefit.regress

You don't need to call this method because it is invoked by the other
methods as needed. After you call setData(), you can call regress() at
any time to get the status of the regression for the current data.
Do the least squares line fit ( if not already done ) linefit . regress You don ' t need to call this method because it is invoked by the other methods as needed . After you call setData () you can call regress () at any time to get the status of the regression for the current data .
def regress
      return @regressOK if @doneRegress
      unless @gotData
         puts "No valid data input - can't do regression" unless @hush
         return false
      end
      sumx, sumy, @sumxx, sumyy, sumxy = computeSums()
      @sumSqDevx = @sumxx - sumx ** 2 / @numxy
      if @sumSqDevx != 0
         @sumSqDevy  = sumyy - sumy ** 2 / @numxy
         @sumSqDevxy = sumxy - sumx * sumy / @numxy
         @slope      = @sumSqDevxy / @sumSqDevx
         @intercept  = (sumy - @slope * sumx) / @numxy
         @regressOK = true
      else
         puts "Can't fit line when x values are all equal" unless @hush
         @sumxx = @sumSqDevx = nil
         @regressOK = false
      end
      @doneRegress = true
      return @regressOK
   end
def regress return @regressOK if @doneRegress unless @gotData puts "No valid data input - can't do regression" unless @hush return false end sumx , sumy , @sumxx , sumyy , sumxy = computeSums ( ) @sumSqDevx = @sumxx - sumx ** 2 / @numxy if @sumSqDevx != 0 @sumSqDevy = sumyy - sumy ** 2 / @numxy @sumSqDevxy = sumxy - sumx * sumy / @numxy @slope = @sumSqDevxy / @sumSqDevx @intercept = ( sumy - @slope * sumx ) / @numxy @regressOK = true else puts "Can't fit line when x values are all equal" unless @hush @sumxx = @sumSqDevx = nil @regressOK = false end @doneRegress = true return @regressOK end
Do the least squares line fit (if not already done)
linefit.regress
Do the least squares line fit ( if not already done ) linefit . regress