export function media(valores) { return valores.reduce((a, b) => a + b, 0) / valores.length; } export function desvioPadrao(valores) { if (valores.length < 2) return 0; const m = media(valores); const variancia = media(valores.map((v) => (v - m) ** 2)); return Math.sqrt(variancia); } export function correlacaoPearson(xs, ys) { if (xs.length < 2 || xs.length !== ys.length) return null; const mx = media(xs); const my = media(ys); const numerador = xs.reduce((soma, x, i) => soma + (x - mx) * (ys[i] - my), 0); const denomX = Math.sqrt(xs.reduce((soma, x) => soma + (x - mx) ** 2, 0)); const denomY = Math.sqrt(ys.reduce((soma, y) => soma + (y - my) ** 2, 0)); if (denomX === 0 || denomY === 0) return null; return numerador / (denomX * denomY); }