vendredi 21 mai 2021

Two step probability draw with python: Combine probability weighting function and a draw from a truncuated normal distribution

I want to draw a random value (r) with python according to a specific probability function:

The value should be a fixed constant with a probability (p) and with a probability (1-p) the value is randomly drawn from a normal distribution in the interval (a,b).

From my point of view, the function consists of two draws:

First draw: a probability weighting function with probabilties p and (1-p).

Second draw: a draw from a truncated normal distribution in the interval (a,b).

f.e.constant = 10; p =0,3; 1-p = 0,7, a=5, b=15

My idea was:

r = random.choices([constant,random.normal()], weights=(0.3, 0.7))

However, it does not seem to work and I don't know how to include the interval (a,b).

Hopefully, someone can help me.Many thanks!




Aucun commentaire:

Enregistrer un commentaire