Sampling from Below-Truncated Normal Distributions
Statistics & ExperimentsModel answerLast updated
Identify a left-truncated normal distribution, write its probability functions, and compare sampling algorithms like inverse-CDF transform and rejection methods.
Assume you generate random numbers from a standard normal distribution, but you immediately drop any output that falls at or below $1$.
- Identify the mathematical name for this resulting probability distribution.
- State the formal Probability Density Function (PDF) and Cumulative Distribution Function (CDF) for this conditional distribution (for general mean $\mu$, standard deviation $\sigma$, and lower truncation threshold $a = 1$).
- Detail at least two distinct techniques to generate random samples directly from this truncated distribution. Compare their computational efficiency, numerical stability, and implementation trade-offs.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Name of the Distribution
This distribution is a left-truncated normal distribution (or lower-truncated normal distribution) truncated below at $a = 1$.
More generally, it represents the conditional distribution of a normal random variable $X \sim \mathcal{N}(\mu, \sigma^2)$ subject to the event $X > a$.
Note on terminology: Do not confuse truncation with censoring. Truncation completely discards values outside the valid range, altering the sample space. Censoring retains out-of-range observations but reassigns their values to the boundary cutoff $a$.
2. Formal PDF and CDF Definitions
Let $X \sim \mathcal{N}(\mu, \sigma^2)$ with lower truncation point $a$. Define the standardized cutoff: $$\alpha = \frac{a - \mu}{\sigma}$$
Let $\phi(z) = \frac{1}{\sqrt{2\pi}} e^{-z^2/2}$ be the standard normal PDF, and $\Phi(z) = P(Z \le z)$ be the standard normal CDF.
Probability Density Function (PDF)
Conditioning on $X > a$ requires renormalizing the original density by $P(X > a) = 1 - \Phi(\alpha)$:
$$f(x \mid X > a) = \begin{cases} \frac{\frac{1}{\sigma} \phi\left(\frac{x - \mu}{\sigma}\right)}{1 - \Phi(\alpha)} & \text{for } x > a \ 0 & \text{for } x \le a \end{cases}$$
Cumulative Distribution Function (CDF)
For $x > a$, the CDF evaluates the conditional probability $P(X \le x \mid X > a)$:
$$F(x \mid X > a) = \begin{cases} \frac{\Phi\left(\frac{x - \mu}{\sigma}\right) - \Phi(\alpha)}{1 - \Phi(\alpha)} & \text{for } x > a \ 0 & \text{for } x \le a \end{cases}$$
Numerical Check ($\mu = 0, \sigma = 1, a = 1$)
- Cutoff: $\alpha = 1$.
- Normal survival probability: $P(Z > 1) = 1 - \Phi(1) \approx 0.1587$.
- Expected Value: $E[X \mid X > 1] = \mu + \sigma \lambda(\alpha)$, where $\lambda(\alpha) = \frac{\phi(\alpha)}{1 - \Phi(\alpha)}$ is the Inverse Mills Ratio. $$\lambda(1) = \frac{\phi(1)}{1 - \Phi(1)} \approx \frac{0.2420}{0.1587} \approx 1.525$$ Thus, the mean shifts from $0$ to approximately $1.525$.
3. Direct Random Sampling Methods
Method 1: Inverse CDF (Inverse Transform Sampling)
The Inverse Transform Theorem states that if $U \sim \text{Uniform}(0, 1)$, then $X = F^{-1}(U)$ follows CDF $F$.
- Draw $U \sim \text{Uniform}(0, 1)$.
- Set $F(X \mid X > a) = U$ and solve for $X$: $$X = \mu + \sigma \cdot \Phi^{-1}\Big( \Phi(\alpha) + U \cdot (1 - \Phi(\alpha)) \Big)$$
- Pros: Exact, deterministic computational time per draw (1 uniform random draw per sample), zero wasted samples.
- Cons/Numerical Stability: For large cutoffs (e.g., $\alpha > 5$), $1 - \Phi(\alpha) \approx 0$ under standard floating-point arithmetic. $\Phi(\alpha)$ rounds to $1.0$, causing $\Phi^{-1}(1.0) = \infty$.
- Tail Fix: For extreme right tails, rephrase using the survival function $\Phi(-z)$: $$X = \mu - \sigma \cdot \Phi^{-1}\Big( V \cdot \Phi(-\alpha) \Big) \quad \text{where } V \sim \text{Uniform}(0,1)$$
Method 2: Naive Rejection Sampling
- Draw $Z \sim \mathcal{N}(\mu, \sigma^2)$.
- If $Z > a$, accept $Z$; otherwise, reject $Z$ and repeat.
- Pros: Trivially easy to implement; requires no inverse CDF or special function libraries.
- Cons: Efficiency depends entirely on $P(X > a) = 1 - \Phi(\alpha)$.
- For $a = 1, \mu = 0, \sigma = 1$, the acceptance rate is $\approx 15.87%$. On average, it takes $\approx 6.3$ proposals per accepted draw, which is reasonable.
- If $a = 5$, the acceptance rate drops to $\approx 2.87 \times 10^{-7}$, rendering the sampler useless.
Method 3: Exponential Proposal Rejection Sampling (Robert, 1995)
For severe tail truncation ($\alpha \gg 0$), propose samples from a shifted Exponential distribution $g(z)$ scaled to fit the normal tail.
- Propose $Z = \alpha + E / \lambda$, where $E \sim \text{Exp}(1)$ and $\lambda > 0$.
- Compute acceptance probability ratio $r(Z) = \exp\left(-\frac{(Z - \lambda)^2}{2}\right)$.
- Generate $U \sim \text{Uniform}(0, 1)$. If $U < r(Z)$, return $X = \mu + \sigma Z$; else reject.
Setting the optimal decay parameter $\lambda^* = \frac{\alpha + \sqrt{\alpha^2 + 4}}{2}$ yields high acceptance rates that approach $100%$ as $\alpha \to \infty$.
Implementation Example (Python)
import numpy as np
from scipy.special import ndtr, ndtri
def sample_truncated_normal_icdf(n, mu=0.0, sigma=1.0, a=1.0, seed=None):
"""Method 1: Inverse-CDF method (tail-stabilized)."""
rng = np.random.default_rng(seed)
alpha = (a - mu) / sigma
# Draw uniform variates
u = rng.uniform(0, 1, size=n)
# Use survival formulation for numerical stability: P(Z > alpha) = ndtr(-alpha)
p_tail = ndtr(-alpha)
z = -ndtri(u * p_tail)
return mu + sigma * z
def sample_truncated_normal_naive(n, mu=0.0, sigma=1.0, a=1.0, seed=None):
"""Method 2: Naive rejection sampling."""
rng = np.random.default_rng(seed)
alpha = (a - mu) / sigma
acc_rate = ndtr(-alpha)
samples = []
needed = n
while needed > 0:
# Batch proposal based on expected acceptance rate
batch_size = max(int(needed / acc_rate * 1.2), 100)
proposals = rng.normal(loc=mu, scale=sigma, size=batch_size)
valid = proposals[proposals > a]
samples.append(valid[:needed])
needed -= len(valid[:needed])
return np.concatenate(samples)
# Validation check
if __name__ == "__main__":
n_draws = 100_000
samples_icdf = sample_truncated_normal_icdf(n_draws, mu=0, sigma=1, a=1, seed=42)
print(f"Min sample value: {samples_icdf.min():.4f}") # Should be > 1.0
print(f"Sample Mean: {samples_icdf.mean():.4f}") # Theoretical ~ 1.5252
print(f"Sample Variance: {samples_icdf.var():.4f}") # Theoretical ~ 0.1990