SciencesPo (version 1.3.8)

draw.norm: Shades Normal Distribuion

Description

Produces a plot of a normal density distribution with shaded areas.

Usage

draw.norm(below = NULL, above = NULL, pcts = c(0.025, 0.975), mu = 0,
  sigma = 1, numpts = 500, color = "gray", dens = 40,
  justabove = FALSE, justbelow = FALSE, lines = FALSE, between = NULL,
  outside = NULL)

Arguments

below
sets a lower endpoint.
above
sets an upper endpoint.
pcts
the
mu
the mean.
sigma
standard deviations.
numpts
the number os points/observations to drawn upon.
color
the color of the area.
dens
the density of the color.
justabove
just plots the upper tail.
justbelow
just plots the lower tail.
lines
to draw lines.
between
plots between specified points.
outside
alternative "outside" area.

Value

  • A plot with a normal distribution density with shaded areas

encoding

UTF-8

Examples

Run this code
draw.norm()
draw.norm(below=-1.5)
draw.norm(below=-1.5,justbelow=TRUE)
draw.norm(above=1.5, justabove=TRUE)
draw.norm(below=-1.5,above=1.5)
draw.norm(between=c(-4,0),color="black")
draw.norm(between=c(0,4),color="black")
draw.norm(between=c(-1,+1),color="darkgray")
title("P[-1 < z < 1] = 68%")
draw.norm(between=c(-2,+2),color="darkgray")
title("P[-2 < z < 2] = 95%")
draw.norm(between=c(-3,+3),color="darkgray")
title("P[-3 < z < 3] = 99.7%")
draw.norm(between = c(-1.75, 0, 2, 0.5, -1))  ## Plots between specified points
draw.norm(below=50,justbelow=TRUE,color="black",mu=47.3,sigma=9.3)

## Can plot one and then another on top of it using lines = TRUE
draw.norm(mu=2, sigma=10, outside=c(-3, 12), dens=15)
draw.norm(mu=2, sigma=15, between=c(-3, 12),lines=TRUE, col="blue",dens=15)
## Example: Plotting a Hypothesis Test for the mean
## Truth:      mu.true  = 8
## Hypothesis: mu.ho    = 6
## Generate Data Under Truth
mu.true = 5 ## Alternative Mean
mu.ho   = 6
sig     = 8
N       = 250 ## Sample Size

std.err = sig/sqrt(N)
crits = qnorm(c(0.025,0.975),mean=mu.ho, sd = std.err)
draw.norm(outside = crits, mu = mu.ho, sigma = std.err,dens=15)
draw.norm(between = crits, mu = mu.true, sigma = std.err, lines=TRUE, color="green",dens=15)

Run the code above in your browser using DataLab