Last active
April 8, 2016 02:32
-
-
Save liammclennan/51749b8217cc21962931696a00715162 to your computer and use it in GitHub Desktop.
Draw a normal probability distribution
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
mean=132; sd=13 | |
lb=105; ub=159 | |
x <- seq(-4,4,length=100)*sd + mean | |
hx <- dnorm(x,mean,sd) | |
plot(x, hx, type="n", xlab="Duration (days)", ylab="", | |
main="Duration Probability Distribution", axes=FALSE) | |
i <- x >= lb & x <= ub | |
lines(x, hx) | |
polygon(c(lb,x[i],ub), c(0,hx[i],0), col="red", density=5) | |
area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) | |
result <- paste("P(",lb,"< Duration <",ub,") =", | |
signif(area, digits=3), " mean = ",mean) | |
mtext(result,3) | |
axis(1, at=seq(40, 180, 20), pos=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment