Michael K
Michael K

Reputation: 2288

Sample from tail of normal distribution in Python

I'm writing some simulations and I've found I need to oversample the tails of a normal distribution in order to get enough samples with a low value for a particular variable. Is there anything better than this?

from scipy.stats import norm, uniform
tail_high = .01
n_samples = 1000
tail_rvs = norm.ppf(uniform.rvs(0, tail_high, n_samples))

Upvotes: 0

Views: 1419

Answers (1)

ev-br
ev-br

Reputation: 26030

Assuming you really need to sample from a normal distribution, you can probably DIY http://en.m.wikipedia.org/wiki/Marsaglia_polar_method or http://en.m.wikipedia.org/wiki/Box–Muller_transform

There is an open issue for truncnorm as currently implemented in scipy https://github.com/scipy/scipy/issues/2477. The original ticket gives links to several alternative implementations.

Upvotes: 1

Related Questions