michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: function regress(DATAPOINTS,SX,SY,SXY,SX2) michael@0: { michael@0: b1 = (DATAPOINTS * SXY - SX * SY) / (DATAPOINTS * SX2 - SX * SX); michael@0: b0 = (SY - b1 * SX ) / DATAPOINTS; michael@0: return b1 " * x + " b0; michael@0: } michael@0: michael@0: BEGIN { michael@0: if (!Skip) Skip = 0; michael@0: if (Interval) michael@0: { michael@0: Count = 0; michael@0: IntervalCount = 0; michael@0: } michael@0: } michael@0: michael@0: NR>Skip { michael@0: sx += $1; michael@0: sy += $2; michael@0: sxy += $1 * $2; michael@0: sx2 += $1 * $1; michael@0: #print NR " " sx " " sy " " sxy " " sx2 michael@0: michael@0: if (Interval) michael@0: { michael@0: if(Count == Interval-1) michael@0: { michael@0: IntervalCount += 1; michael@0: michael@0: print NR-Count, "-", NR, ": ", regress(Count,isx,isy,isxy,isx2); michael@0: michael@0: Count = 0; michael@0: isx = 0; michael@0: isy = 0; michael@0: isxy = 0; michael@0: isx2 = 0; michael@0: } michael@0: else michael@0: { michael@0: Count += 1; michael@0: isx += $1; michael@0: isy += $2; michael@0: isxy += $1 * $2; michael@0: isx2 += $1 * $1; michael@0: } michael@0: } michael@0: } michael@0: michael@0: END { michael@0: if(Interval) { michael@0: print NR-Count, "-", NR, ": ", regress(Count,isx,isy,isxy,isx2); michael@0: } michael@0: print regress(NR-Skip, sx, sy, sxy, sx2); michael@0: }