corr

corr(A,B)

Try it yourself:


Measure linear association with corr

corr(A, B) calculates the correlation between two equally sized data sets. Correlation summarizes whether values tend to rise and fall together: a positive result suggests they move in the same direction, a negative result suggests opposite movement, and a result near zero indicates little linear association.

Reading the result

Pearson correlation lies between -1 and 1. A value of 1 represents a perfect positive linear relationship, while -1 represents a perfect negative one. Correlation is unitless, so it is useful for comparing variables with different scales. For the related spread measures, see mean, standard deviation, and variance.

Practical example

Use corr([1,2,3,4], [2,4,6,8]) to confirm a perfectly positive linear pattern. In real measurements, first remove missing or nonnumeric entries and make sure that positions correspond: the first value of A must describe the same observation as the first value of B. filter and subset can help prepare aligned data.

Important caveats

Correlation does not show causation and can be misleading when an outlier dominates a small sample. It measures linear rather than every possible relationship; curved data can have a low correlation even when clearly related. The inputs must have compatible lengths and enough varying numeric values—correlation is not meaningful when either series has zero spread. Use median and mad to explore robust summaries alongside it.

All functions