相関係数を指定してベ​クトルを作成する方法​はありますか?

既知の相関係数 rho と ベクトル X から新たなベクトル Y を得る方法を教えてください。

 Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Nov 2012

0 votes

直接的な関数はございません。下記のように実現することができます。
function b = wantcorrelation(a,rho)
%WANTCORRELATION Get a vector having specified correlation with another
if abs(rho)==1
b = sign(rho) * a;
return
end
% Standardize a
a = a(:);
n = numel(a);
a = (a - mean(a)) ./ std(a);
% Get standardized noise
z = randn(size(a));
z = (z - mean(z)) ./ std(z);
% Remove any random correlation and re-standardize
r = (a'*z) / (n-1);
z = z - r*a;
z = (z - mean(z)) ./ std(z);
% Create new variable with desired correlation
lambda = rho / sqrt(1-rho^2);
b = z + lambda*a;

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!