From 8b44d43c83bd36a7a2768e35a6260499f7cb6428 Mon Sep 17 00:00:00 2001 From: Anton Nesterov Date: Wed, 25 Sep 2024 13:19:01 +0200 Subject: [PATCH] add expr --- expr.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 expr.ts diff --git a/expr.ts b/expr.ts new file mode 100644 index 0000000..0d08113 --- /dev/null +++ b/expr.ts @@ -0,0 +1,9 @@ +import pl from "npm:nodejs-polars" + +export function residuals(x: pl.Expr, y: pl.Expr): pl.Expr { + const xM = x.minus(x.mean()) + const yM = y.minus(y.mean()) + const xMSQ = xM.pow(2) + const beta = xM.dot(yM).div(xMSQ.sum()) + return yM.minus(beta.mul(xM)) +} \ No newline at end of file