Chapter 7 Normal model
7.1 Plot curve
- To plot a normal curve, we use `dnorm’ for a range of \(x\) values.
When does the Normal curve start to disappear?
7.2 Plot area under curve (Ext)
- To plot an area under the curve, we use
polygon
.
curve(dnorm(x), xlim = c(-2, 2),ylab="",axes=FALSE)
abline(h = 0)
sequence = seq(-2, 0.8, 0.1)
polygon(x = c(sequence,0.8,-2),
y = c(dnorm(c(sequence)),0,0),
col = "purple")
axis(1, at=c(-2,-1,0,0.8,1,2), pos=0)
7.3 Add normal to a histogram
hist(mtcars$wt,prob=T)
m=mean(mtcars$wt)
s=sd(mtcars$wt)
curve(dnorm(x, mean=m, sd=s),
col="darkgreen", lwd=2, add=TRUE)