Generating samples from certain regions of a Gaussian distribution

132 Views Asked by At

Let $X$ be a Gaussian random variable where for simplicity, $X \sim N(0,1)$. I am interested in generating samples of $X$ in the following cases: $X \mid X \in (a,b)$ where $a < b$ or $X \mid X > b$. I am aware that I can do rejection sampling for this and especially for the latter, Wikipedia says (under rejection sampling) that exponential tilting is a very efficient manner to generate samples for $X \mid X>b$. I am wondering though: is there a better way to do this without rejection sampling? In other words, do algorithms exist wherein the above scenarios can be sampled by just a simple scaling/translation of a random variable that can be easily sampled?

Thoughts/comments appreciated. Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

It is easy enough if you have the cumulative distribution function $\Phi(x)$ and inverse cumulative distribution function $\Phi^{-1}(y)$ of a standard normal distribution:

  • Generate $U$ uniformly distributed on the interval $(\Phi(a),\Phi(b))$
  • Let $X = \Phi^{-1}(U)$

and if you just want to ensure $X \gt a$ then $b=+\infty$ and $\Phi(b)=1$

For example in R:

a <- 2
b <- 3
n <- 8
set.seed(1)
qnorm(runif(n, min=pnorm(a), max=pnorm(b))) 

gives

[1] 2.118457 2.175760 2.308311 2.714952 2.087221 2.694532 2.802697 2.382023