Chap 5 Distributions and Densities Pg 222

library(plogr)
# Define the Mean and Stdev
mean=70
sd=10

x <- seq(-3.5,3.5,length=100)*sd + mean
y <- dnorm(x,mean,sd)
# Plot x vs. y as a line graph
plot(x, y, type="l")
polygon(c(x[x>=50], 50), c(y[x>=50], 0), col="red")

p50 <- 1-pnorm(50,mean,sd)
p50
## [1] 0.9772499
# Plot x vs. y as a line graph
plot(x, y, type="l")
polygon(c(x[x<=60], 60), c(y[x<=60], 0), col="red")

p60 <- pnorm(60,mean,sd)
p60
## [1] 0.1586553
# Plot x vs. y as a line graph
plot(x, y, type="l")
polygon(c(x[x>=90], 90), c(y[x>=90], 0), col="red")

p90 <-1- pnorm(90,mean,sd)
p90
## [1] 0.02275013
# Plot x vs. y as a line graph

# prob 25d
mean=70; sd=10
lb=60; ub=80


x <- seq(-4,4,length=100)*sd + mean
hx <- dnorm(x,mean,sd)

plot(x, hx, type="n", xlab="X values", ylab="",
  main="Normal Distribution", axes=FALSE)

i <- x >= lb & x <= ub
lines(x, hx)
polygon(c(lb,x[i],ub), c(0,hx[i],0), col="red") 

area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd)

result <- paste("P(",lb,"< X <",ub,") =",
   signif(area, digits=3))
mtext(result,3)
axis(1, at=seq(40, 160, 20), pos=0) 

p60_80_first <-pnorm(80,mean,sd)
p60_80_2nd <-pnorm(60,mean,sd)
p60_80 <-p60_80_first-p60_80_2nd
p60_80
## [1] 0.6826895