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