Statistics Functions
statistics.correlation()
Compute Pearson linear correlation by default or Spearman rank correlation with method='ranked'. Equal-length nonconstant data of length at least two are required. Association does not establish causation.
Formal Syntax & Structure
python syntaxpython
statistics.correlation(x, y, /, *, method='linear')Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | sequence of real numbers | Paired observations, same length as the other sequence. |
| y | sequence of real numbers | Paired observations, same length as the other sequence. |
| method | str | Choose linear or ranked correlation. |
Return Value
float
Floating-point result; finite precision and domain restrictions apply.
Working Example
Example Snippetpython
import statisticsprint(round(statistics.correlation([1, 2, 3], [6, 4, 2]), 6))