MATH 2565 W 2007 Section M Week 8 R Script for Normal Distributions

From MathWiki

   ##
   ##
   ##    Chapter 5.3
   ##    Normal distribution
   ##
   ##


   ## Classical bell curve distribution


   std.normal.density <- function(x) (1/sqrt(2*pi))*exp(- (x^2) / 2)
   dd <- data.frame( x = seq( -4,4, .05))
   dd$nd <- std.normal.density( dd$x )
   plot( nd ~ x, dd, type = 'l')
   
   # same as
   
   plot( dnorm(x) ~ x, dd, type = 'l')
   
   
   # Using R to calculate probabilities for the standard normal
   
   
   # Prob Z between -1 and 1
   
   pnorm(1)    # Pr ( Z < 1)
   pnorm(-1)   # Pr ( Z < -1)
   pnorm(1) - pnorm( -1)   # Pr ( -1 < Z < 1 )
   pnorm(2) - pnorm( -2)
   pnorm(3) - pnorm( -3)
   pnorm(4) - pnorm( -4)
   
   #
   #  Probabilities for other normals
   #
   
   # Pr ( 80 < IQ < 110 )
   # = Pr (  (80 - 100)/15 < Z < (110 -100)/15)   # standardize
   
   - pnorm((80 - 100)/15) + pnorm( (110 -100)/15)