Search All of the Math Forum:

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

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

 Messages: [ Previous | Next ]
 Tom Lane Posts: 858 Registered: 12/7/04
Re: Generation of Correlated Data
Posted: Apr 30, 2013 10:01 AM

> 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;
cov(z)
mean(z)

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

-- Tom

Date Subject Author
8/12/08 devasiri mdp
8/12/08 Roger Stafford
4/29/13 Chetan
4/30/13 Tom Lane
5/6/13 Chetan
8/16/08 devasiri mdp
8/17/08 Roger Stafford
8/17/08 devasiri mdp
9/15/08 devasiri mdp
8/17/08 Greg Heath
8/17/08 Roger Stafford