0

Given $X$ a random variable with a normal distribution, what is the best procedure to simulate $X|X\in[a;b]\cup[c;d]$, i.e. we want to simulate the truncated normal distribution only on the intervals $[a;b]$ or $[c;d]$.

I have already seen a question asked on this forum in Truncated normal distribution over a union of intervals, but the answer gives no indication of how to simulate a sample of this law.

M. A. Kacef
  • 101
  • 3
  • 1
    I am astonished by your claim that the answer "gives no indication of how to sample," because it *includes working code!* Please take another look. However, that code implements the (potentially lethally inefficient) rejection method. Instead, just invert the CDF. Alternatively, sample from a mixture of two Normals, each truncated on one of the intervals. – whuber Dec 20 '21 at 18:40

1 Answers1

0

Honestly, I don't think you need to do anything more sophisticated than simulating from an unconstrained Normal distribution, and then exclude values outside of your intervals (example in R):

mu = 0
sigma = 1
low1 = -1
high1 = -.5
low2 = 0
high2 = 1
x = rnorm(n, mu, sigma)
in_interval = (x > low1 & x < high1) | (x > low2 & x < high2)
trunc_x = x[in_interval]

There are also more efficient, but more complicated solutions, that let you sample directly from an arbitrary distribution.

Eoin
  • 4,543
  • 15
  • 32
  • This can be *incredibly* inefficient. Try it with a standard Normal distribution truncated to $(-10,-6)\cup(6,10),$ for instance. – whuber Dec 20 '21 at 18:37