My data looks something this (for example):

Salary  Age  Zip  Class
 60000   35    5    Yes  
 50000   52    4     No  
 10000   25    3    Yes  
 70000   56    6    Yes  
 20000   48    1     No  

That is, there are several variables (attributes) like salary, age, etc. I know how to find the distribution of these univariate variables... (for e.g. Gaussian, uniform, etc.)
Correct me if I am wrong, but the distributions are also called marginal PDFs of this multivariate dataset...

I can also find the covariance matrix and correlation in this data (can be easily found from the data).

I need to generate some artificial data which resembles this data. That is, some more tuples like:

Salary  Age  Zip  Class  
 56000   40    3    Yes  
 64000   22    1     No  

I know how to sample random data following the univariate distributions... That is, I can generate random data for salary, random data for age, etc. individually.

However, since these attributes are correlated, how do I create random data such that it obeys the distribution as well as covariance/correlation?

  • $\begingroup$ You could probably use the multidimensional CLT. In particular you could use the following function in R: <code> mvrnorm(n = 1, mu, Sigma, tol = 1e-6, empirical = FALSE, EISPACK = FALSE) </code> $\endgroup$ May 26 '15 at 15:03

I would try using copulas. This may sound mystical at first, but it's very easy to do in terms of coding. For instance, look at this MATLAB example.

You are right that you have marginals, i.e. unconditional distribution of the variables. You are also right that since the variables are correlated it would not be ideal to simulate them as if they were independent, i.e. simply using marginals.

What copulas do is to combine marginals in such a way that the variables would be generated correlated. You have literally three steps to apply copulas.

  1. Calculate the correlation matrix.
  2. Plug the correlation matrix into the copula to get correlated set of uniform variables.
  3. Plug the uniform variables into the inverse marginals to get the correlated variables.

You don't even need to parameterize the marginals, and use instead the empirical distributions. It's a very easy way to start your analysis.

  • $\begingroup$ Yes I tried with Copula ! Its working exactly the way you described.. But the results are a little weird... The correlation between the variables of the existing data and between the variables of artificial data I generated using copula don't match... Implying that the data generated isn't perfect... Any idea why is it so? $\endgroup$
    – Radhika
    May 27 '15 at 16:11
  • $\begingroup$ @Radhika Read on that link which I gave in the answer. The correlation would match exactly only in special cases, e.g. for Gaussian distribution using Gaussian copula. I just gave you the starting point to play with and get familiar with a tool. You will have to pick an appropriate copula and correlation measures such as Pearson or Spearman. $\endgroup$
    – Aksakal
    May 27 '15 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.