diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2026-09-02 22:27:04 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2026-09-02 22:27:04 +0200 |
| commit | d68fdea59aaf05877438bfba669c96d716523765 (patch) | |
| tree | 17913de3ed05cbc494b44b4ffabece46608c89f0 /pbt/ts/src/stats.ts | |
| parent | 7f69074b259f479b05777ba915a6ef3481a749af (diff) | |
| download | lambda-nantes-main.tar.gz | |
Diffstat (limited to 'pbt/ts/src/stats.ts')
| -rw-r--r-- | pbt/ts/src/stats.ts | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/pbt/ts/src/stats.ts b/pbt/ts/src/stats.ts index 8c50856..8f9832c 100644 --- a/pbt/ts/src/stats.ts +++ b/pbt/ts/src/stats.ts @@ -86,15 +86,11 @@ export function chiSquare (samples : number [], expected : number []) : number { throw new Error("Samples and expected arrays must have the same length."); } - let chiSquareValue = 0; - for (let i = 0; i < samples.length; i++) { - const observed = samples[i]; + return samples.reduce((acc, observed, i) => { const exp = expected[i]; if (exp === 0) { throw new Error("Expected frequency cannot be zero."); } - chiSquareValue += Math.pow(observed - exp, 2) / exp; - } - - return chiSquareValue; + return acc + Math.pow(observed - exp, 2) / exp; + }, 0); } |
