diff options
| author | wukong <wukong@longaeva> | 2018-10-01 21:07:06 -0700 |
|---|---|---|
| committer | wukong <wukong@longaeva> | 2018-10-01 21:07:06 -0700 |
| commit | 97304f19e701d18ca753b90b993fffa1c58c5f9a (patch) | |
| tree | b287c59bc74d547ae5344ce7a6fdb93754c832cc | |
| parent | 6375b4618439865e2c975aaa5bb30623e9082df3 (diff) | |
fixed header output error in diff, added print statement for a few key coords to solutions of the quadratic regression;
Diffstat (limited to '')
| -rw-r--r-- | diff.awk | 1 | ||||
| -rw-r--r-- | quad_reg.awk | 25 |
2 files changed, 24 insertions, 2 deletions
@@ -33,6 +33,7 @@ NR == 1 { if (n < NF) printf(OFS) } + printf(ORS) } NF { diff --git a/quad_reg.awk b/quad_reg.awk index 0620808..7d9304a 100644 --- a/quad_reg.awk +++ b/quad_reg.awk @@ -34,7 +34,7 @@ NF > 0 { mean[y] = sum[y]/count[y] mean2[y] = sum2[y]/count[y] - ### difference from the mean + ### delta, difference from the mean delta[y] = $y - mean[y] delta2[y] = $y*$y - mean2[y] sum_delta[y] += delta[y] @@ -62,6 +62,13 @@ NF > 0 { s_x2x2[x,y] = sum_delta_x2x2[x,y]/(count[x,y] - 1) s_x2y[x,y] = sum_delta_x2y[x,y]/(count[x,y] - 1) } + else { + s_xx[x,y] = 0 + s_xy[x,y] = 0 + s_xx2[x,y] = 0 + s_x2x2[x,y] = 0 + s_x2y[x,y] = 0 + } bc_den[x,y] = (s_xx[x,y]*s_x2x2[x,y] - s_xx2[x,y]*s_xx2[x,y]) if (bc_den[x,y]) { @@ -80,6 +87,18 @@ NF > 0 { # correlation sum_delta2[y] ? r[x,y] = sqrt(1 - sum_err2[x,y]/sum_delta2[y]) : r[x,y] = 0 + + # vertex of parabola + if (c[x,y]) { + xv[x,y] = -1.0*b[x,y]/(2.0*c[x,y]) + yv[x,y] = -1.0*(b[x,y]*b[x,y])/(4.0*c[x,y]) + a[x,y] + } + + # roots (x-intercept) + if (c[x,y]) { + rx0[x,y] = (-1.0*b[x,y] - sqrt(b[x,y]*b[x,y] - 4.0*a[x,y]*c[x,y]))/(2.0*c[x,y]) + rx1[x,y] = (-1.0*b[x,y] + sqrt(b[x,y]*b[x,y] - 4.0*a[x,y]*c[x,y]))/(2.0*c[x,y]) + } } } else @@ -91,8 +110,10 @@ END { for (x=1; x<=nf_max; x++) { for (y=1; y<=nf_max; y++) { if (x != y && r[x,y]) { - printf(OFMT OFS "(%s)" OFS " = (" OFMT ")(%s)^2" OFS " + (" OFMT ")(%s)" OFS " + (" OFMT ")" ORS, + printf(OFMT OFS "(%s)" OFS " = (" OFMT ")(%s)^2" OFS " + (" OFMT ")(%s)" OFS " + (" OFMT ")", 10.0*log(r[x,y]*r[x,y])/log(10), header[y], c[x,y], header[x], b[x,y], header[x], a[x,y]) + printf("\t[" OFMT "," OFMT "][" OFMT "," OFMT "][" OFMT "," OFMT "]" OFS" [" OFMT "," OFMT "]" ORS, + rx0[x,y], 0, rx1[x,y], 0, 0, a[x,y], xv[x,y], yv[x,y]) } } } |
