Correlation functions
This module provides various functions for estimating correlation between two or more sets of data.
Methods
================================== =========== Method Description ================================== =========== f_oneway_ (data) Perform one-way ANOVA pearsonr_ (x, y) Pearson correlation coefficient spearmanr_ (x, y, alternative) Spearman correlation coefficient kendalltau_ (x, y, alternative) Kendall's tau coefficient pointbiserialr_ (x, y) Point biserial correlation linregress_ (x, y, alternative) Linear regression with coefficient ================================== ===========
Description
.. _f_oneway:
.. function:: f_oneway(data)
:module: stats.correlation
:param data: Array<Vector<Float64>>
:return: (Float64, Float64)
Perform one-way ANOVA on the given samples. The return value
is the pair (F statistic, p-value).
.. _pearsonr:
.. function:: pearsonr(x, y)
:module: stats.correlation
:param T: type parameter, implements Float
:param x: Vector<T>
:param y: Vector<T>
:return: (Float64, Float64)
Estimate correlation between two sets of data. The return value
is the pair (coefficient, p-value).
Example:
1. Compute Pearson correlation coefficient on hand-picked input.
::
let (r, prob) = pearsonr(
vector([1.0, 2.0, 3.0, 4.0, 5.0]),
vector([10.0, 9.0, 2.5, 6.0, 4.0])
)
Result: r = :math:`-0.7426106572325057`, prob = :math:`0.1505558088534455`.
2. Compute Pearson correlation coefficient on generated data according
to equation :math:`y = x + e`.
::
let r = Random(2)
let s: Float64 = 0.5
let x = randn(r, 500, 0.0, 1.0)
let e = randn(r, 500, 0.0, 0.5)
let y = x + e
let (pr, prob) = pearsonr(x, y)
Result: r = :math:`0.894537`, prob = :math:`0.0`.
.. _spearmanr:
.. function:: spearmanr(x, y[, alternative])
:module: stats.correlation
:param T: type parameter, implements Real, Hashable
:param x: Vector<T>
:param y: Vector<T>
:param alternative: String, one of "two-sided" (default), "less", "greater"
:return: (Float64, Float64)
Compute the Spearman correlation coefficient. The returned value
is the pair (coefficient, p-value).
.. _kendalltau:
.. function:: kendalltau(x, y, alternative)
:module: stats.correlation
:param T: type parameter, implements Real, Hashable
:param x: Vector<T>
:param y: Vector<T>
:param alternative: String, one of "two-sided" (default), "less", "greater"
:return: (Float64, Float64)
Compute the Kendall's tau correlation coefficient. The returned value
is the pair (coefficient, p-value).
.. _pointbiserialr:
.. function:: pointbiserialr(x, y)
:module: stats.correlation
:param T: type parameter, implements Float
:param x: Vector<T>
:param y: Vector<T>
:return: (Float64, Float64)
Compute the point biserial correlation coefficient and its p-value. This
is the same as Pearson's coefficient.
.. _linregress:
.. function:: linregress(x, y[, alternative])
:module: stats.correlation
:param x: Vector<Float64>
:param y: Vector<Float64>
:param alternative: String, one of "two-sided" (default), "less", "greater"
:return: LinregressResult
Compute the linear regression between two series of data. The returned
result contains the following:
* slope: Float64
* intercept: Float64
* rvalue: Float64
* pvalue: Float64
* stderr: Float64, standard error on the slope
* intercept_stderr: Float64, standard error on the intercept