I am interested in generating correlated, skewed data in order to evaluate the application of a statistical approach to a data set I am analyzing. Specifically, I have two correlated variables, and I can determine the correlation coefficient ($R^2$) between the two, as well as the shape, scale and location of each skewed distribution using the sn.em command within the sn package for R.

I can generate a skewed distribution using the rsnorm function within the VGAM package. However, I cannot tell it to generate a second vector that is correlated to the first, also skewed, and has its own specific set of shape, scale and location parameters as calculated from the data.

Any advice on how to do this would be greatly appreciated, and thank you in advance!


3 Answers 3


You can get the marginal distributions you want easily enough, but you may not also be able to get the populations to be linearly correlated as you wish - the two desires are not generally compatible.

However, one thing you can do is specify a monotonic measure of correlation (like Spearman's rho or Kendall's tau); these survive monotonic transformation intact. As such, you can use copulas to generate two uniform marginals with the desire amount of association, and then transform the margins to exactly what you desire.

By judicious choice of copula family you may be able to get the linear correlation close to the desired one.


An approach that I've had surprising success with (in Mathematica -- I don't know R) takes any set of pairs $(x_1,y_1),\ldots,(x_n,y_n)$ and tries to create a specified correlation by re-pairing the data. That is, iterating over all $n(n-1)/2$ pairs $(i,j)$, swap $y_i$ and $y_j$ if it will bring the correlation closer to the specified value. In general, it seems to work best when the $n(n-1)/2$ absolute differences among $x_1,\ldots,x_n$ contain few ties, and similarly for $y_1,\ldots,y_n$. (And, of course, when the specified correlation is not ruled out by the marginal distributions.)


Let r be the correlation value you want


Simulate two random variables from the same density, they should be independent. If not you should insure their correlation is 0 (maybe a cholesky decomposition?)


[1] 0.007983692

Use this formula to get the correlated second variable y1


[1] 0.3006946

This will only work for you if (1) the two input random variables' have the same distribution and (2) you only care about one of the output random variables' distribution.

  • $\begingroup$ Hi, Thank you for the response. The two variables do not come from the same distribution. They have different means, and as a result different parameters for shape, scale and location of their respective skewed distributions. I just attempted using your script anyways, with the following distributions (parameters taken from my data): library(VGAM) #generate distributions x=rsnorm(220,shape= 10.6852380,scale= 1.2881360,location=0.2788605 ) y=rsnorm(220,shape= 19.695530,scale= 28.453448,location= 3.316043 ) #specify r2 r= 0.6835 #generate new y values y1=xr+ysqrt(1-r^2) summary(lm(y1~x)) $\endgroup$
    – colin
    Sep 17, 2013 at 23:13
  • $\begingroup$ This answer will not work for your parameters. If you have data why don't you use a resampling/bootstrap? $\endgroup$
    – Seth
    Sep 18, 2013 at 0:33
  • $\begingroup$ I want to simulate data to do a monte carlo simulation to show the structure of my analysis and the groups my data were sampled from are not generating spurious results. I am confident in the analysis, but the reviewer is not. I don't think resampling could achieve this. $\endgroup$
    – colin
    Sep 18, 2013 at 1:45
  • $\begingroup$ While I don't know your reviewer, I would say that resampling makes fewer assumption when compared to simulation from parameters. $\endgroup$
    – Seth
    Sep 26, 2013 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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