correlation
correlation(x, y=None, method='pearson')Correlation between two samples, or a correlation matrix.
Mirrors the C# Correlation class of the Numerics library: the paired-vector forms (Correlation.Pearson/Spearman/KendallsTau, both IList<double> overloads) and the Pearson/Spearman column-pairwise matrix overloads (Pearson(double[,])/ Spearman(double[,])).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | array_like | A numeric vector (paired-vector form, y required), or a 2D array-like (a NumPy array, nested list, or pandas-style object coercible via numpy.asarray) with one column per variable (matrix form, y omitted). |
required |
| y | array_like | A numeric vector of the same length as x, or None (the default) to compute the correlation matrix of x’s columns instead. |
None |
| method | ('pearson', 'spearman', 'kendall') | Which coefficient to compute. "kendall" is rejected when y is None: upstream has no KendallsTau(double[,]) overload, so there is no Kendall matrix form to compute. |
"pearson" |
Returns
| Name | Type | Description |
|---|---|---|
| float or numpy.ndarray | With y given, a single correlation coefficient; with y None, a (p, p) array, p the number of columns of x. |
Examples
>>> from corehydropy import correlation
>>> round(correlation([14, 8, 32, 7, 3, 15], [10, 5, 7, 4, 3, 8]), 6)
0.545027