Skip to content

Instantly share code, notes, and snippets.

@Dasonk
Created February 20, 2014 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dasonk/9118126 to your computer and use it in GitHub Desktop.
Save Dasonk/9118126 to your computer and use it in GitHub Desktop.
How to calculate normal distribution probabilities in various languages
# http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html
import scipy.stats
Z = scipy.stats.norm(0, 1)
Z.pdf(0)
Z.cdf(0)
# mean of 5, standard deviation of 2
X = scipy.stats.norm(5, 2)
X.cdf(5)
X.cdf(0)
# dnorm gives the pdf for the normal at x
dnorm(1)
# pnorm gives the cdf for the normal at x
# P(Z < 1)
pnorm(1)
# They also accept parameters to specify the mean and standard deviation
# X ~ N(mean = 2, sd = 4)
# P(X < 1)
pnorm(1, 2, 4)
# If we have something like
# X ~ N(mean = 2, sd = 4)
# and want to find
# P(1 < X < 2)
# we can provide multiple arguments for x and take the difference
diff(pnorm(c(1,2), 2, 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment