5

Is there any function that allow me to compute the CDF probability of a normal distribution, given a mean and sigma ? i.e. for example P( X < x ) given the normal distribution with $\bar{x}$ and $\sigma$.

I think boost have this, but I think that it is just for the standard normal distribution.

shn
  • 5,116
  • 9
  • 34
  • 62
  • if you're using C++11 there's `erf()` in ``. See @Dirk's answer below to use this with non-standard normal distributions. – Shep Jun 06 '12 at 13:31

1 Answers1

7

You scale -- any N(m, s) can be turned into N(0,1) by dividing by s and subtracting m. So all you need is a cdf for N(0,1) which is provided by a number of libraries.

Here is a simple R example:

R> pnorm(1.96, 0, 1)          # compute cdf of 1.96 for N(0,1)
[1] 0.975002
R> pnorm(1.96*3 + 2, 2, 3)    # mu + sd*1.96 is really the same for N(mu, sd)
[1] 0.975002
R> 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Oh well boost can do it directly ! even of it is not a standard distribution. However I didn't knew about the scale, thanks. – shn Jun 06 '12 at 13:30
  • I didn't even check, but I glanced at R's pnorm.c and it does just that as well of m and s (defaulting to 0 and 1, of course) are not supplied. As the operation is so simple and general, most libraries do in fact offer it. But still handy to know the scaling trick :) – Dirk Eddelbuettel Jun 06 '12 at 13:34
  • To whoever just randomly downvoted without leaving a comment: Huh? – Dirk Eddelbuettel Aug 26 '14 at 13:40