corrcoef(): matrix
Correlation coefficients of arrays.
Calculates the correlation coefficients between arrays or matrices. Returns the sample correlation coefficient matrix for matrix input, or the correlation matrix between two input arrays/matrices.
Perfect positive correlation between identical arrays
Perfect positive correlation between identical arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, 2, 3], [1, 2, 3]), [ [1, 1], [1, 1], ]);
Perfect negative correlation between reversed arrays
Perfect negative correlation between reversed arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, 2, 3], [3, 2, 1]), [ [1, -1], [-1, 1], ]);
Zero correlation between orthogonal sequences
Zero correlation between orthogonal sequences
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, -1, 1, -1], [1, 1, -1, -1]), [ [1, 0], [0, 1], ]);
Explicit sample flag matches the default behaviour
Explicit sample flag matches the default behaviour
import { assertEquals } from "jsr:@std/assert"; assertEquals( corrcoef([2, 4, 6, 8], [1, 2, 3, 4]), corrcoef([2, 4, 6, 8], [1, 2, 3, 4], 1), );
Population flag (0) is supported for array inputs
Population flag (0) is supported for array inputs
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, 2, 3], [3, 2, 1], 0), [ [1, -1], [-1, 1], ]);
Matrix input with linearly related columns
Matrix input with linearly related columns
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([ [1, 2, -1], [2, 4, -2], [3, 6, -3], ]), [ [1, 1, -1], [1, 1, -1], [-1, -1, 1], ]);
Matrix input with independent columns
Matrix input with independent columns
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([ [1, 1, -1], [-1, 1, 1], [1, -1, 1], [-1, -1, -1], ]), [ [1, 0, 0], [0, 1, 0], [0, 0, 1], ]);
Symmetry for swapped array inputs
Symmetry for swapped array inputs
import { assertEquals } from "jsr:@std/assert"; assertEquals( corrcoef([1, 2, 3, 4], [4, 3, 2, 1]), corrcoef([4, 3, 2, 1], [1, 2, 3, 4]), );
Matrix of correlation coefficients
corrcoef(x: matrix,flag?: number,): matrix
Correlation coefficients of arrays.
Calculates the correlation coefficients between arrays or matrices. Returns the sample correlation coefficient matrix for matrix input, or the correlation matrix between two input arrays/matrices.
Perfect positive correlation between identical arrays
Perfect positive correlation between identical arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, 2, 3], [1, 2, 3]), [ [1, 1], [1, 1], ]);
Perfect negative correlation between reversed arrays
Perfect negative correlation between reversed arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, 2, 3], [3, 2, 1]), [ [1, -1], [-1, 1], ]);
Zero correlation between orthogonal sequences
Zero correlation between orthogonal sequences
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, -1, 1, -1], [1, 1, -1, -1]), [ [1, 0], [0, 1], ]);
Explicit sample flag matches the default behaviour
Explicit sample flag matches the default behaviour
import { assertEquals } from "jsr:@std/assert"; assertEquals( corrcoef([2, 4, 6, 8], [1, 2, 3, 4]), corrcoef([2, 4, 6, 8], [1, 2, 3, 4], 1), );
Population flag (0) is supported for array inputs
Population flag (0) is supported for array inputs
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([1, 2, 3], [3, 2, 1], 0), [ [1, -1], [-1, 1], ]);
Matrix input with linearly related columns
Matrix input with linearly related columns
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([ [1, 2, -1], [2, 4, -2], [3, 6, -3], ]), [ [1, 1, -1], [1, 1, -1], [-1, -1, 1], ]);
Matrix input with independent columns
Matrix input with independent columns
import { assertEquals } from "jsr:@std/assert"; assertEquals(corrcoef([ [1, 1, -1], [-1, 1, 1], [1, -1, 1], [-1, -1, -1], ]), [ [1, 0, 0], [0, 1, 0], [0, 0, 1], ]);
Symmetry for swapped array inputs
Symmetry for swapped array inputs
import { assertEquals } from "jsr:@std/assert"; assertEquals( corrcoef([1, 2, 3, 4], [4, 3, 2, 1]), corrcoef([4, 3, 2, 1], [1, 2, 3, 4]), );
x: matrix
Input array or matrix
Matrix of correlation coefficients