2

I have a 20 element array, x, of floating point numbers, ex:

x = [ 0.35945087, 0.08999019, 0.51313128, 0.75455967, 0.50654956, 0.12404178, 0.25115332, 0.94167661, 0.95727792, 0.35572299, 0.65264679, 0.09416763, 0.861585, 0.19661212, 0.62882119, 0.1180147, 0.17153433, 0.07275386, 0.01895795, 0.00578392]

This data is not normally distributed, it rather follows a power law distribution.

I need to generate a second array, y, which is correlated with x and the correlation coefficient is 0.70.

How do I do this with python?

3
  • Any code to provide? Commented May 9, 2016 at 14:22
  • Possibly duplicate with Generating random correlated x and y points using Numpy Commented May 9, 2016 at 14:38
  • This is not a duplicate of that question. This is a more complicated problem because of the constraint on the marginal distribution. Commented May 9, 2016 at 15:00

2 Answers 2

1

This is one of those things that sounds very easy to ask, but is complicated when you get down to the details. I can only point you in the right direction rather than give you a straightforward recipe.

Notionally, what you need to do is construct a bivariate distribution where the marginal distributions are both power laws (presumably, the same power law) but has the desired correlation coefficient.

(X, Y) ~ f(x, y) s.t. X ~ powerlaw(params); Y ~ powerlaw(params); corr(X, Y) = 0.7

This can be done through a copula.

For each sample x[i] that you have, you find the univariate conditional distribution Y ~ f(x=x[i], y) and sample from it.

Note that the correlation coefficient is probably not particularly meaningful when applied to power law distributions. Power law distributions do not in general have finite first and second moments.

Sign up to request clarification or add additional context in comments.

Comments

-3
y = [number * 0.7 for number in x]

Is this what you need ?

3 Comments

unfortunately this won't work. According to your approach the correlation between x and y remains 1.
The correlation coefficient is still 1.
Thanks for your submission to StackOverflow! In general, it is highly recommended to post your solution with some explanation rather than ask for feedback from the original poster (OP).

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.