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

NameTypeDescription
xsequence of real numbersPaired observations, same length as the other sequence.
ysequence of real numbersPaired observations, same length as the other sequence.
methodstrChoose 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))
Python Reference