WEIGHTEDCORRS returns a symmetric matrix R of weighted correlation coefficients calculated from an input T-by-N matrix Y whose rows are observations and whose columns are variables and an input T-by-1 vector w of weights for the observations. This function may be a valid alternative to CORRCOEF if observations are not all equally relevant and need to be weighted according to some theoretical hypothesis or knowledge.
R = WEIGHTEDCORRS(Y, w) returns a positive semidefinite matrix R, i.e. all its eigenvalues are non-negative (see Example 1 in help section).
WEIGHTEDCORRS is such that WEIGHTEDCORRS(Y, w) == WEIGHTEDCORRS(a * Y + b, w) where a and b are two real numbers (see Example 1 in help section).
Furthermore, the result provided by the function doesn't change if the unit system of each column of Y is changed through an arbitrary affine transformation y = a * x + b, where a and b are two real numbers, with a > 0 (see Example 2 in help section).
If w = ones(size(Y, 1), 1), no difference exists between WEIGHTEDCORRS(Y, w) and CORRCOEF(Y) (see Example 4 in help section).
**************************************
Example: how to use the function
T = 1000; % number of observations
w = 1:T; % choose weights
Y(:, 1) = (1:T) - T / 2 - 0.5;
Y(:, 2) = rand * Y(:, 1) .^ 2 + rand; % Parabolic relation (symmetric)
r1 = corrcoef(Y) % Traditional Correlation Matrix
r2 = weightedcorrs(Y, w) % Weighted Correlation Matrix
**************************************
Lots of examples in the help section |