MCPcopy Create free account
hub / github.com/arguiot/TheoremJS / correlation

Method correlation

__test__/theorem.js:203–219  ·  view source on GitHub ↗
(array1, array2)

Source from the content-addressed store, hash-verified

201 return average
202 }
203 correlation(array1, array2) {
204 if (array1.length != array2.length) {
205 throw "[TheoremJS]: Correlation error, arrays are not the same size"
206 }
207 const average1 = this.average(...array1).toNumber()
208 const average2 = this.average(...array2).toNumber()
209 let up = 0;
210 let down1 = 0;
211 let down2 = 0;
212 for (var i = 0; i < array1.length; i++) {
213 up += (array1[i] - average1)*(array2[i] - average2)
214 down1 += Math.pow(array1[i] - average1, 2)
215 down2 += Math.pow(array2[i] - average2, 2)
216 }
217 const result = up / Math.sqrt(down1 * down2)
218 return new BigNumber(Math.round(result * 10 ** 10) / 10 ** 10)
219 }
220 median() {
221 let array = [...arguments]
222 if (typeof array[0] == 'object') {

Callers 1

test.jsFile · 0.80

Calls 4

averageMethod · 0.95
sqrtMethod · 0.80
roundMethod · 0.80
powMethod · 0.45

Tested by

no test coverage detected