Skip to content

Correlations API¤

stamox.correlation.cor(x: ArrayLike, y: Optional[ArrayLike] = None, axis: int = 0, method: str = 'pearson') -> ArrayLike ¤

Calculates correlation between two arrays.

Parameters:

Name Type Description Default
x ArrayLike

The first array.

required
y Optional[ArrayLike]

The second array. Defaults to None.

None
axis int

Axis along which the correlation is calculated. Defaults to 0.

0
method str

Method used for calculating correlation. Defaults to "pearson".

'pearson'

Returns:

Type Description
ArrayLike

Correlation between two arrays.

Exceptions:

Type Description
NotImplementedError

If the specified method is not supported.

Examples:

>>> import jax.numpy as jnp
>>> from stamox.functions import cor
>>> x = jnp.array([1, 2, 3, 4, 5])
>>> y = jnp.array([5, 6, 7, 8, 7])
>>> cor(x, y)
Array(0.8320503, dtype=float32)

stamox.correlation.pearsonr(x: ArrayLike, y: Optional[ArrayLike] = None, axis: int = 0) -> ArrayLike ¤

Computes Pearson correlation coefficient for two arrays.

Parameters:

Name Type Description Default
x ArrayLike

An array-like object containing the first set of data.

required
y Optional[ArrayLike]

An optional array-like object containing the second set of data. If not

None
axis int

The axis along which the correlation coefficient should be computed.

0

Returns:

Type Description
ArrayLike

An array-like object containing the Pearson correlation coefficient.

Examples:

>>> import jax.numpy as jnp
>>> from stamox.functions import pearsonr
>>> x = jnp.array([1, 2, 3, 4, 5])
>>> y = jnp.array([5, 6, 7, 8, 7])
>>> pearsonr(x, y)
Array(0.8320503, dtype=float32)

stamox.correlation.spearmanr(x: ArrayLike, y: Optional[ArrayLike] = None, axis: int = 0) -> ArrayLike ¤

Calculates a Spearman rank-order correlation coefficient and the p-value to test for non-correlation.

Parameters:

Name Type Description Default
x ArrayLike

An array of values.

required
y Optional[ArrayLike]

An array of values. Defaults to None.

None
axis int

The axis along which to calculate. Defaults to 0.

0

Exceptions:

Type Description
ValueError

If the supplied axis argument is greater than 1 or if the number of dimensions of the array is greater than 2.

Returns:

Type Description
ArrayLike

A array-like containing the Spearman rank-order correlation coefficient and the p-value to test for non-correlation.

Examples:

>>> import jax.numpy as jnp
>>> from stamox.functions import spearmanr
>>> x = jnp.array([1, 2, 3, 4, 5])
>>> y = jnp.array([5, 6, 7, 8, 7])
>>> spearmanr(x, y)
Array(0.8207823038101196, dtype=float32)