The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Generation of Correlated Data
Replies: 10   Last Post: May 6, 2013 9:34 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Tom Lane

Posts: 858
Registered: 12/7/04
Re: Generation of Correlated Data
Posted: Apr 30, 2013 10:01 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> Is it possible to generalize this to data sets with any mean, variance and
> covariance?

I didn't see the original posting, but it sounds like you want to specify an
exact mean and covariance. This is not the same as generating from a
theoretical mean and covariance (which is what I believe most people ought
to want to do most of the time), because the result is less random than it
should be. But the question comes up from time to time. Here's an example:

% Desired mean and covariance
Mu = [10 15.5 9.99];
Sigma = [5 -3 0;-3 4 1;0 4 10];

% Create too-perfect sample with zero mean and identity covariance
x = randn(100,length(Mu));
z = zscore(x); % if you don't have Statistics Toolbox, subtract mean and
divide by std
c = chol(cov(z));
z = z/c;

% Apply desired mean and covariance
z = z*chol(Sigma);
z = bsxfun(@plus,Mu,z);

-- Tom

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.