|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 function regress(DATAPOINTS,SX,SY,SXY,SX2) |
|
6 { |
|
7 b1 = (DATAPOINTS * SXY - SX * SY) / (DATAPOINTS * SX2 - SX * SX); |
|
8 b0 = (SY - b1 * SX ) / DATAPOINTS; |
|
9 return b1 " * x + " b0; |
|
10 } |
|
11 |
|
12 BEGIN { |
|
13 if (!Skip) Skip = 0; |
|
14 if (Interval) |
|
15 { |
|
16 Count = 0; |
|
17 IntervalCount = 0; |
|
18 } |
|
19 } |
|
20 |
|
21 NR>Skip { |
|
22 sx += $1; |
|
23 sy += $2; |
|
24 sxy += $1 * $2; |
|
25 sx2 += $1 * $1; |
|
26 #print NR " " sx " " sy " " sxy " " sx2 |
|
27 |
|
28 if (Interval) |
|
29 { |
|
30 if(Count == Interval-1) |
|
31 { |
|
32 IntervalCount += 1; |
|
33 |
|
34 print NR-Count, "-", NR, ": ", regress(Count,isx,isy,isxy,isx2); |
|
35 |
|
36 Count = 0; |
|
37 isx = 0; |
|
38 isy = 0; |
|
39 isxy = 0; |
|
40 isx2 = 0; |
|
41 } |
|
42 else |
|
43 { |
|
44 Count += 1; |
|
45 isx += $1; |
|
46 isy += $2; |
|
47 isxy += $1 * $2; |
|
48 isx2 += $1 * $1; |
|
49 } |
|
50 } |
|
51 } |
|
52 |
|
53 END { |
|
54 if(Interval) { |
|
55 print NR-Count, "-", NR, ": ", regress(Count,isx,isy,isxy,isx2); |
|
56 } |
|
57 print regress(NR-Skip, sx, sy, sxy, sx2); |
|
58 } |