# [Numpy-discussion] Correlated distributions (?)

nicky van foreest vanforeest at gmail.com
Thu Aug 16 18:14:52 EDT 2012

```Hi,

>>     once again, my apologies for a (possibly) very ignorant question,
>> my google-fu is failing me... also because I am not sure of what
>> exactly I should look for.
>>
>> My problem is relatively simple. Let's assume I have two Python
>> objects, A and B, and one of their attributes can assume a value of
>> "True" or "False" depending on the results of a uniform random
>> distribution sample, i.e.:
>>
>> probability_A = 0.95
>> probability_B = 0.86
>>
>> A.has_failed = False
>> B.has_failed = False
>>
>> if numpy.random.random() < probability_A:
>>     A.has_failed = True
>>
>> if numpy.random.random() < probability_B:
>>     B.has_failed = True
>>
>> Now, I know that there is a correlation factor between the failing/not
>> failing of A and the failing/not failing of B. Specifically, If A
>> fails, then B should have 80% more chance of failing, but I have been
>> banging my head to find out how I should modify the "probability_B"
>> number (or the extremes of the uniform distribution, if that makes
>> sense) in order to reflect that correlation.

I don't think you actually can. You seem to want to simulate
conditional events, and for that you have to take the conditioning
events serious. Hence, I am inclined to solve your problem like this.

if A.has_failed:
if numpy.random.random() < probability_B_given_Ahasfailed:
B.has_failed = True
else:
B.has_failed = False

You have to specify the threshold probability_B_given_Ahasfailed separately.

on this topic is not particularly revealing in my opinion BTW.)

HTH

Nicky

>>
>> I have been looking at correlated distributions, but it appears that
>> most of the results I have found relate to normal distributions, there
>> is very little about non-normal (and especially uniform)
>> distributions.
>>
>> It's also very likely that I am not looking in the right direction, so
>> I would appreciate any suggestion you may share.
>
>
> easiest, I guess, is to work with a discrete distribution with 4 states,
> where states reflect the joint event (a, b)
> True, True
> True, False
> ...
>
> Then you have 3 probabilities to choose any amount of dependence, and
> marginal probabilities.
>
> (more complicated, correlated Probit)
>
> to generate random numbers, a recipe of Charles on the mailing list, or a
> new version of numpy might be helpful.
>
>
> Josef
>
>>
>>
>>
>> Andrea.
>>
>> "Imagination Is The Only Weapon In The War Against Reality."
>> http://xoomer.alice.it/infinity77/
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

```