1

I'm trying to create a graph that looks similar to this: http://stats.seandolinar.com/wp-content/uploads/2014/12/Probabiliy-of-Finding-Someone-Taller-than-6-Comparison.png

To do that, I'm following this code example:

     curve(dnorm(x,0,1),xlim=c(-3,3),main='Normal Density')
cord.x <- c(-2, seq(-2,-1,.01),-1)
cord.y <- c(0, dnorm(seq(-2,-1,.01)),0)
polygon(cord.x,cord.y,col='skyblue')

I then tried to modify that code for my own data, which is trying to shade the area between 79 and 120:

lbound <- (79-94)/6.8
ubound <- (120-94)/6.8
curve(dnorm(x,94,6.8), xlim=c(70,120), main="normal density")
cord.x <- c(79,seq(79,120,.01),120)
cord.y <- c(0, dnorm(seq(79,120,.01)),0)
polygon(cord.x,cord.y,col='skyblue')

I'm not sure what is going wrong, I've tried to replace all the data points with both z scores and actual data, but none are plotting the graph. Anybody who knows how to do it would be appreciated.

Eleven-87
  • 53
  • 4

1 Answers1

1

You need to define mean and sd in the second dnorm function.

curve(dnorm(x, mean=94, sd=6.8), xlim=c(70,120), main="normal density")
cord.x <- c(79, seq(79,120,.01), 120)
cord.y <- c(0, dnorm(seq(79,120,.01), mean=94, sd=6.8), 0)
polygon(cord.x, cord.y, col='skyblue')

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58