mathjs 11.10.1 → 11.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +10 -2
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +4 -4
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesCorr.generated.js +36 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +7 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesCorr.generated.js +36 -0
- package/lib/cjs/entry/dependenciesNumber.generated.js +7 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +25 -24
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +4 -3
- package/lib/cjs/entry/pureFunctionsAny.generated.js +46 -33
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +26 -13
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/cjs/expression/embeddedDocs/function/statistics/corr.js +15 -0
- package/lib/cjs/factoriesAny.js +7 -0
- package/lib/cjs/factoriesNumber.js +10 -4
- package/lib/cjs/function/statistics/corr.js +85 -0
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesCorr.generated.js +28 -0
- package/lib/esm/entry/dependenciesAny.generated.js +1 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesCorr.generated.js +28 -0
- package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +26 -25
- package/lib/esm/entry/impureFunctionsNumber.generated.js +5 -4
- package/lib/esm/entry/pureFunctionsAny.generated.js +35 -23
- package/lib/esm/entry/pureFunctionsNumber.generated.js +21 -9
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/esm/expression/embeddedDocs/function/statistics/corr.js +8 -0
- package/lib/esm/factoriesAny.js +1 -0
- package/lib/esm/factoriesNumber.js +1 -0
- package/lib/esm/function/statistics/corr.js +74 -0
- package/lib/esm/version.js +1 -1
- package/package.json +2 -2
- package/types/index.d.ts +8 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
import { factory } from '../../utils/factory.js';
|
2
|
+
var name = 'corr';
|
3
|
+
var dependencies = ['typed', 'matrix', 'mean', 'sqrt', 'sum', 'add', 'subtract', 'multiply', 'pow', 'divide'];
|
4
|
+
export var createCorr = /* #__PURE__ */factory(name, dependencies, _ref => {
|
5
|
+
var {
|
6
|
+
typed,
|
7
|
+
matrix,
|
8
|
+
sqrt,
|
9
|
+
sum,
|
10
|
+
add,
|
11
|
+
subtract,
|
12
|
+
multiply,
|
13
|
+
pow,
|
14
|
+
divide
|
15
|
+
} = _ref;
|
16
|
+
/**
|
17
|
+
* Compute the correlation coefficient of a two list with values, For matrices, the matrix correlation coefficient is calculated.
|
18
|
+
*
|
19
|
+
* Syntax:
|
20
|
+
*
|
21
|
+
* math.corr(A, B)
|
22
|
+
*
|
23
|
+
* Examples:
|
24
|
+
*
|
25
|
+
* math.corr([1, 2, 3, 4, 5], [4, 5, 6, 7, 8]) // returns 1
|
26
|
+
* math.corr([1, 2.2, 3, 4.8, 5], [4, 5.3, 6.6, 7, 8]) // returns 0.9569941688503644
|
27
|
+
* math.corr(math.matrix([[1, 2.2, 3, 4.8, 5], [1, 2, 3, 4, 5]]), math.matrix([[4, 5.3, 6.6, 7, 8], [1, 2, 3, 4, 5]])) // returns DenseMatrix [0.9569941688503644, 1]
|
28
|
+
*
|
29
|
+
* See also:
|
30
|
+
*
|
31
|
+
* median, mean, min, max, sum, prod, std, variance
|
32
|
+
*
|
33
|
+
* @param {Array | Matrix} A The first array or matrix to compute correlation coefficient
|
34
|
+
* @param {Array | Matrix} B The second array or matrix to compute correlation coefficient
|
35
|
+
* @return {*} The correlation coefficient
|
36
|
+
*/
|
37
|
+
return typed(name, {
|
38
|
+
'Array, Array': function ArrayArray(A, B) {
|
39
|
+
return _corr(A, B);
|
40
|
+
},
|
41
|
+
'Matrix, Matrix': function MatrixMatrix(xMatrix, yMatrix) {
|
42
|
+
return matrix(_corr(xMatrix.toArray(), yMatrix.toArray()));
|
43
|
+
}
|
44
|
+
});
|
45
|
+
/**
|
46
|
+
* Calculate the correlation coefficient between two arrays or matrices.
|
47
|
+
* @param {Array | Matrix} A
|
48
|
+
* @param {Array | Matrix} B
|
49
|
+
* @return {*} correlation coefficient
|
50
|
+
* @private
|
51
|
+
*/
|
52
|
+
function _corr(A, B) {
|
53
|
+
if (Array.isArray(A[0]) && Array.isArray(B[0])) {
|
54
|
+
var correlations = [];
|
55
|
+
for (var i = 0; i < A.length; i++) {
|
56
|
+
correlations.push(correlation(A[i], B[i]));
|
57
|
+
}
|
58
|
+
return correlations;
|
59
|
+
} else {
|
60
|
+
return correlation(A, B);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
function correlation(A, B) {
|
64
|
+
var n = A.length;
|
65
|
+
var sumX = sum(A);
|
66
|
+
var sumY = sum(B);
|
67
|
+
var sumXY = A.reduce((acc, x, index) => add(acc, multiply(x, B[index])), 0);
|
68
|
+
var sumXSquare = sum(A.map(x => pow(x, 2)));
|
69
|
+
var sumYSquare = sum(B.map(y => pow(y, 2)));
|
70
|
+
var numerator = subtract(multiply(n, sumXY), multiply(sumX, sumY));
|
71
|
+
var denominator = sqrt(multiply(subtract(multiply(n, sumXSquare), pow(sumX, 2)), subtract(multiply(n, sumYSquare), pow(sumY, 2))));
|
72
|
+
return divide(numerator, denominator);
|
73
|
+
}
|
74
|
+
});
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "11.
|
3
|
+
"version": "11.11.0",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"complex.js": "^2.1.1",
|
30
30
|
"decimal.js": "^10.4.3",
|
31
31
|
"escape-latex": "^1.2.0",
|
32
|
-
"fraction.js": "
|
32
|
+
"fraction.js": "4.3.4",
|
33
33
|
"javascript-natural-sort": "^0.7.1",
|
34
34
|
"seedrandom": "^3.0.5",
|
35
35
|
"tiny-emitter": "^2.1.0",
|
package/types/index.d.ts
CHANGED
@@ -2970,6 +2970,14 @@ declare namespace math {
|
|
2970
2970
|
normalization: 'unbiased' | 'uncorrected' | 'biased'
|
2971
2971
|
): MathNumericType
|
2972
2972
|
|
2973
|
+
/**
|
2974
|
+
* Calculate the correlation coefficient between two matrix.
|
2975
|
+
* @param {Array | Matrix} x The first array or matrix to compute correlation coefficient
|
2976
|
+
* @param {Array | Matrix} y The second array or matrix to compute correlation coefficient
|
2977
|
+
* @returns correlation coefficient
|
2978
|
+
*/
|
2979
|
+
corr(x: MathCollection, y: MathCollection): MathType
|
2980
|
+
|
2973
2981
|
/*************************************************************************
|
2974
2982
|
* String functions
|
2975
2983
|
************************************************************************/
|