Correlation[v,w]
gives the correlation between the vectors v and w.
Correlation[a,b]
gives the cross-correlation matrix for the matrices a and b.
Correlation[a]
gives the auto-correlation matrix for observations in matrix a.
Correlation[dist]
gives the correlation matrix for the multivariate symbolic distribution dist.
Correlation[dist,i,j]
gives the (i,j)
correlation for the multivariate symbolic distribution dist.
Correlation
Correlation[v,w]
gives the correlation between the vectors v and w.
Correlation[a,b]
gives the cross-correlation matrix for the matrices a and b.
Correlation[a]
gives the auto-correlation matrix for observations in matrix a.
Correlation[dist]
gives the correlation matrix for the multivariate symbolic distribution dist.
Correlation[dist,i,j]
gives the (i,j)
correlation for the multivariate symbolic distribution dist.
Details
- Correlation is typically used to measure covariation, i.e. whether one variable tends to vary similarly to another.
- For vectors, the correlation estimate Correlation[v,w] is given by
with σv w=Covariance[v,w] and σv=StandardDeviation[v]. - The correlation
is a normalized covariance with
. - For matrices
and
with dimensions
and
and columns indexed as
and
, respectively, Correlation[a,b] is a
matrix with elements given by
: - where Σa b=Covariance[a,b] and σa=StandardDeviation[a] etc.
- For a matrix a with
columns, Correlation[a] is a
matrix given by Correlation[a, a]. - Correlation works with any vector that is VectorQ or matrix that is MatrixQ.
- Correlation[dist,i,j] gives Covariance[dist,i,j]/(σi σj), where σi=StandardDeviation[dist]〚i〛.
- Correlation[dist] gives a correlation matrix with the (i,j)
entry given by Correlation[dist,i,j].
Examples
open all close allBasic Examples (3)
Correlation between two vectors:
Correlation[{a, b}, {x, y}]Refine[%, {a, b, x, y}∈Reals]Correlation matrix for a matrix:
Correlation[{{a, b}, {c, d}}]Refine[%, {a, b, c, d}∈Reals]Correlation matrix for two matrices:
Correlation[{{a, b}, {c, d}}, {{x}, {y}}]//MatrixFormRefine[%, {a, b, c, d, x, y}∈Reals]Scope (14)
Data (8)
Exact input yields exact output:
Correlation[{5, 3 / 4, 1}, {2, 1 / 2, 1}]Correlation[{1, π, 2}, {2, 2, 1}]//SimplifyApproximate input yields approximate output:
Correlation[{1.5, 3, 5, 10}, {2, 1.25, 15, 8}]Correlation[N[{1, 2, 5, 6}, 20], N[{2, 3, 6, 8}, 20]]Correlation between vectors of complexes:
Correlation[{2 + I, 3 - 2I, 5 + 4I}, {I, 1 + 2I, 10 - 5I}]Correlation[RandomReal[1, 10 ^ 7], RandomReal[1, 10 ^ 7]]A structured array can be used (see the guide):
Correlation[SparseArray[{{1, 2} -> 1.2, {2, 2} -> 1, {3, 1} -> 2}]]//MatrixFormCorrelation[IdentityMatrix[2]]//MatrixFormCorrelation[ToeplitzMatrix[4]]//MatrixFormCorrelation[QuantityArray[RandomReal[1, {20, 2}], "Meters"]]//MatrixFormFind the correlation for data involving quantities:
v = Quantity[{2, 3.5, 4, 5}, "Meters"];
w = Quantity[{10, 32, 19, 24.2}, "Pounds"];Correlation[v, w]Correlation between lists of dates:
v = RandomDate[4]w = RandomDate[4]Correlation[v, w]Correlation between matrices of times:
Correlation[RandomTime[{4, 2}], RandomTime[{4, 3}]]//MatrixFormDistributions and Processes (6)
Correlation for a continuous multivariate distribution:
Correlation[BinormalDistribution[ρ]]//MatrixFormCorrelation[BinormalDistribution[ρ], 2, 1]Correlation for a discrete multivariate distribution:
Correlation[MultivariatePoissonDistribution[μ, {2, 3}]]//MatrixFormCorrelation[MultivariatePoissonDistribution[μ, {2, 3}], 2, 1]Correlation controls the orientation and sharpness of a multivariate probability distribution:
dists = {
BinormalDistribution[-0.7],
BinormalDistribution[0],
BinormalDistribution[0.99]
};colors = Table[ColorData[97, i], {i, 3}];
GraphicsRow[Table[
Plot3D[PDF[dists[[i]], {x, y}], {x, -3.5, 3.5}, {y, -3.5, 3.5}, PlotRange -> All, PlotStyle -> {colors[[i]]}, Ticks -> None, MeshStyle -> Opacity[.1], AxesLabel -> {"*x*", "*y*", None}, PlotLabel -> dists[[i]],
ViewPoint -> {0, 2, 2}
]
, {i, 3}
],
ImageSize -> {500, 500 .3}
]Correlation for derived distributions:
Correlation[ProductDistribution[ExponentialDistribution[1], NormalDistribution[3, 5]]]//MatrixForm𝒟 = CopulaDistribution[{"Frank", 2}, {UniformDistribution[{0, 1}], UniformDistribution[{0, 1}]}];Correlation[𝒟]//MatrixForm𝒟 = HistogramDistribution[RandomVariate[BinormalDistribution[.75], 10 ^ 4]];Correlation[𝒟]//MatrixFormCorrelation[BinormalDistribution[.75]]//MatrixFormCorrelation matrix for a random process at times s and t:
Correlation[WienerProcess[][{s, t}]]//MatrixFormCorrelation matrix for TemporalData at times
and
:
td = RandomFunction[WienerProcess[1, 1], {0, 10, 0.05}, 100]Correlation[td[{0.2, 0.3}]]//MatrixFormApplications (3)
Compute the correlation of two financial time series:
gspc = TemporalData[TimeSeries, {{{2058.2, 2020.58, 2002.61, 2025.9, 2062.14, 2044.81, 2028.26, 2023.03,
2011.27, 1992.67, 2019.42, 2022.55, 2032.12, 2063.15, 2051.82, 2057.09, 2029.55, 2002.16,
2021.25, 1994.99, 2020.85, 2050.03, 2041.51, 2062. ... 3719174400,
3719260800, 3719520000, 3719606400, 3719692800}}}, 1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ValueDimensions -> 1, DateFunction -> Automatic, ResamplingMethod ->
{"Interpolation", InterpolationOrder -> 1}}}, True, 314.1];ndx = TemporalData[TimeSeries, {{{4230.2368, 4160.9644, 4110.8301, 4159.9995, 4240.5495, 4213.2758,
4169.9704, 4166.2025, 4145.8414, 4089.6482, 4142.1401, 4171.2143, 4192.0934, 4270.3628,
4278.1424, 4275.7154, 4165.5017, 4140.3756, 4181.3514, 4 ... 3719174400,
3719260800, 3719520000, 3719606400, 3719692800}}}, 1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ValueDimensions -> 1, DateFunction -> Automatic, ResamplingMethod ->
{"Interpolation", InterpolationOrder -> 1}}}, True, 314.1];Correlation[gspc["Values"], ndx["Values"]]Correlation can be used to measure linear association:
data = BlockRandom[SeedRandom[1];Table[RandomVariate[BinormalDistribution[i], 3000], {i, {-.99, -.75, -.25, -.5, 0., .25, .5, .75, .99}}]];Grid[Partition[Table[ListPlot[i, PlotStyle -> Directive[PointSize[Tiny]],
FrameTicks -> None, Frame -> True, Axes -> None, PlotLabel -> Row[{"ρ : ", Correlation[i][[1, 2]]}]], {i, data}],
3]]Correlation can only detect monotonic relationships:
uni = RandomReal[{-3, 3}, 3000];f[x_] := {{x, -Sqrt[Abs[x]] + RandomReal[.5]}, {x, .25x^2 + RandomReal[.5]}, {x, -Sinc[x] + RandomReal[.5]}, {Cos[x], Sin[x] + RandomReal[.5]}}data = f /@ uni;Table[ListPlot[data[[All, i]], Frame -> True, Axes -> None, PlotLabel -> Row[{"ρ : ", Correlation[data[[All, i]]][[1, 2]]}], PlotStyle -> Directive[PointSize[Tiny]], FrameTicks -> None], {i, 4}]HoeffdingD can be used to detect a variety of dependence structures:
Table[HoeffdingD[data[[All, i]]][[1, 2]], {i, 4}]Properties & Relations (7)
The correlation matrix is symmetric and positive semidefinite:
corr = Correlation[RandomVariate[BinormalDistribution[1 / 3], 10 ^ 3]];SymmetricMatrixQ[corr]PositiveSemidefiniteMatrixQ[corr]A correlation matrix is a covariance matrix scaled by standard deviations:
data = RandomReal[5, {20, 5}];s = DiagonalMatrix[1 / StandardDeviation[data]];Correlation[data] == s.Covariance[data].s{a, b} = RandomReal[1, {2, 3, 2}];invS = TensorProduct@@((StandardDeviation /@ {a, b}) ^ -1);Covariance[a, b] invS == Correlation[a, b]Correlation and AbsoluteCorrelation agree for zero mean and unit marginal variances:
𝒟 = BinormalDistribution[ρ];Mean[𝒟]Variance[𝒟]Correlation[𝒟]AbsoluteCorrelation[𝒟]SpearmanRho is Correlation applied to ranks:
data = Transpose@RandomVariate[BinormalDistribution[.8], 100];SpearmanRho[data[[1]], data[[2]]]rnks = Ordering[Ordering[#]]& /@ data;Correlation[rnks[[1]], rnks[[2]]]//NCorrelationFunction for a process is the off-diagonal entry in the correlation matrix:
𝒫 = WienerProcess[μ, σ];Correlation[𝒫[{s, t}], 1, 2]CorrelationFunction[𝒫, s, t]Simplify[%% - %, 0 < s < t]Correlation and Covariance are the same for standardized vectors:
sample = RandomVariate[DiscreteUniformDistribution[{{2, 3}, {4, 5}}], 200];Covariance[sample] === Correlation[sample]Covariance[Standardize[sample]] === Correlation[sample]The diagonal elements of a correlation matrix are equal to 1:
Diagonal[Correlation[RandomReal[10, {100, 4}]]]See Also
Covariance AbsoluteCorrelation CorrelationFunction Variance CentralMoment Expectation CorrelationTest
Function Repository: FirstOrderCorrelation IntraclassCorrelation
History
Introduced in 2007 (6.0) | Updated in 2010 (8.0) ▪ 2023 (13.3) ▪ 2024 (14.1)
Text
Wolfram Research (2007), Correlation, Wolfram Language function, https://reference.wolfram.com/language/ref/Correlation.html (updated 2024).
CMS
Wolfram Language. 2007. "Correlation." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/Correlation.html.
APA
Wolfram Language. (2007). Correlation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Correlation.html
BibTeX
@misc{reference.wolfram_2026_correlation, author="Wolfram Research", title="{Correlation}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/Correlation.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_correlation, organization={Wolfram Research}, title={Correlation}, year={2024}, url={https://reference.wolfram.com/language/ref/Correlation.html}, note=[Accessed: 12-June-2026]}