Skip to content

Instantly share code, notes, and snippets.

@mrkn
Created January 22, 2014 04:40
Show Gist options
  • Save mrkn/8553585 to your computer and use it in GitHub Desktop.
Save mrkn/8553585 to your computer and use it in GitHub Desktop.
xs <- (0:1000 - 500) / 150
x0975 <- qnorm(0.975)
y0975 <- dnorm(x0975)
plot(dnorm(xs) ~ xs, type="n", main="standard normal distribution", xlab=NA, ylab=NA)
polygon(x=c(-x0975, -x0975, xs[abs(xs) < x0975], x0975, x0975),
y=c( 0, y0975, dnorm(xs[abs(xs) < x0975]), y0975, 0),
density=-1, border=NA, col=grey(0.8))
lines(dnorm(xs) ~ xs)
arrows( x0975, 0, x0975, y0975, code=0)
arrows(-x0975, 0, -x0975, y0975, code=0)
arrows(-x0975, y0975/2, x0975, y0975/2, code=3, length=0.1)
text(0, y0975/2, c("95% confidence interval"), adj=c(0.5, 1.5))
arrows(-x0975, 0.1, -x0975, y0975+0.01, code=2, length=0.08)
text(-x0975, 0.1, c("-qnorm(1 - 0.05/2)"), adj=c(0.9, -1), cex=0.7)
arrows( x0975, 0.1, x0975, y0975+0.01, code=2, length=0.08)
text( x0975, 0.1, c("qnorm(1 - 0.05/2)"), adj=c(0.1, -1), cex=0.7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment