summaryrefslogtreecommitdiff
path: root/lin_reg.awk
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2026-04-10 23:46:12 -0700
committerwukong <wukong@longaeva>2026-04-10 23:46:12 -0700
commit4c4eb1bd8f003b3b57707badd2dd089ed193a896 (patch)
tree15b62907fffd70c46a9b4369df93ab33c6aa88ac /lin_reg.awk
parente7d1781578e846a7b1d634cd43c8fab00a67b883 (diff)
renamed fir window generators;
minor edits to whitespace and comments for more consistent style;
Diffstat (limited to '')
-rw-r--r--lin_reg.awk17
1 files changed, 11 insertions, 6 deletions
diff --git a/lin_reg.awk b/lin_reg.awk
index 5a9df56..3006e8a 100644
--- a/lin_reg.awk
+++ b/lin_reg.awk
@@ -3,6 +3,7 @@
### lin_reg.awk
# simple linear regression between columns
+
BEGIN {
OFS = ":"
sign = "[+-]?"
@@ -12,23 +13,26 @@ BEGIN {
number = "^" sign "(" decimal "|" fraction ")" exponent "$"
}
+
+# column headers
NR == 1 {
for (n=1; n<=NF; n++)
($n ~ number) ? header[n] = "col" n : header[n] = $n
}
-NF {
- if (NF > nf_max)
- nf_max = NF
- ### iterate over columns
+# read input data
+NF > 0 {
+ (NF > nf_max) ? nf_max = NF : nf_max = nf_max
+
+ # columns
for (y=1; y<=nf_max; y++) {
if ($y == header[n])
continue
if ($y ~ number) {
- ### mean
+ # mean
count[y] += 1
sum[y] += $y
sum2[y] += $y*$y
@@ -38,7 +42,7 @@ NF {
sum_delta[y] += delta1[y]
sum_delta2[y] += delta0[y]*delta1[y]
- ### sample variance
+ # sample variance
#(count[y] > 1) ? var[y] = sum_delta2[y]/(count[y] - 1) : var[y] = ""
# x = row, y = col, trendline: y = A + Bx
@@ -91,6 +95,7 @@ NF {
}
}
+
END {
for (y=1; y<=nf_max; y++) {
for (x=1; x<=nf_max; x++) {