add expr
This commit is contained in:
parent
7e0085ffbd
commit
8b44d43c83
1 changed files with 9 additions and 0 deletions
9
expr.ts
Normal file
9
expr.ts
Normal file
|
@ -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))
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue