Created
February 20, 2014 16:46
-
-
Save Dasonk/9118126 to your computer and use it in GitHub Desktop.
How to calculate normal distribution probabilities in various languages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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