lundi 13 février 2023

r - draw random samples from a uniform distribution with a gap in the interval

I am interested into drawing random samples from a uniform distribution which is spread across 2 intervals: from -2 to -1 and from 1 to 2. Any value which belongs to these intervals should have equal probability of being sampled and the other values (e.g. from -1 to 1) should have 0 probability from being sampled.

The runif function only accepts single numbers as arguments for the upper and lower limit. Thus, it is impossible to make that function sample from two intervals.

Another option would be running two runif functions, one on the interval from -2 to -1, and one on the interval from 1 to 2. However, in this case I explicitly make it so that in each draw there will be an equal number of numbers drawn from each interval.

I want to allow this to vary and, while on the average there will be roughly the same amount of positive and negative numbers, I still need to see some random variation, e.g. draws where more numbers were drawn from the positive interval or vice versa.




Aucun commentaire:

Enregistrer un commentaire