Review the Normal Distribution


On your USB drive, create a new directory, copy model.R to that directory, rename the file in the new directory, double click on the file to open Rstudio. Then copy all of the text below the line and paste it into your Rstudio editor pane.
# A quick review of using pnorm and qnorm
#
#   For a  Standard Normal distribution, N(0,1)
#
# find P(X<1.34)
pnorm( 1.34 )
# find P( X > 1.34)
1 - pnorm( 1.34 )  # first way to do this
pnorm( 1.34, lower.tail=FALSE)
#
# find P( -0.43 < X < 1.73 )
pnorm( 1.73 ) - pnorm( -0.43 )
#
# find P( X < -0.75 or X > 1.14 )
#            first way
pnorm( -0.75 ) + ( 1 - pnorm(1.14))
#            second way
pnorm( -0.75 ) + pnorm(1.14, lower.tail=FALSE)
#            third way
1 - ( pnorm(1.14)-pnorm( -0.75) )
#
# find the value of x such that 
#    P( X < x ) = 0.23
qnorm( 0.23 )
# find the value of x such that 
#    P( X > x ) = 0.23
qnorm( 1 - 0.23 )  # first way
qnorm( 0.23, lower.tail=FALSE)  # second way

# there is another type of problem that we can
# do because the normal distribution is symmetric.
# find x such that 
#  P( -x < X < x ) = 0.58
#  we can find -x by
qnorm( (1 - 0.58)/2)
# we can find x by 
qnorm( 0.21, lower.tail= FALSE)
# or 
qnorm( 0.79 )

#
#  or find x such that 
#  P( X <-x or X>x ) = 0.075
# Because we have a symmetric distribution we 
# also know that this means 
# that P( X < -x ) = 0.075/2 = 0.0375
qnorm( 0.0375 )  # which gives the value for -x
# or we could do
qnorm(0.0375, lower.tail=FALSE) # to get x

######################################################
#  Now, let us try some for non-standard             #
#  normal distributions.  We will do each            #
#  problem twice, once converting to the             #
#  problem to a standard normal, and then the        #
#  second time using the extra parameters of the     #
#  pnorm and qnorm functions                         #  
######################################################
#
#  For a normal population with mean=54.3 and
#  standard deviation 12.7, i.e., N(54.3,12.7)
#  find P( X < 63 )?
#  Convert to a z-score
z <- (63 - 54.3)/ 12.7
z
#  then use pnorm
pnorm( z )
#
# or, just use the expanded pnorm command
pnorm( 63, mean=54.3, sd=12.7)

#######################
# for a N(74.2, 6.54) population find
# P( X > 68)
#
# convert to z-score
z <- (68 - 74.2)/12.7
z
#  use pnorm
1 - pnorm( z )  # looking to the left,
# or
pnorm( z, lower.tail = FALSE)  # looking to the right

# or use the expanded pnorm function
1 - pnorm( 68, mean=74.2, sd=12.7 ) # looking left
# or
pnorm( 68, mean=74.2, sd=12.7, lower.tail=FALSE ) # looking right
#
########################
# for a N(3.2, 0.73) distribution
#  find P( 2.8 < X < 3.6 )
#
# convert both values to z-scores
z_left <- (2.8 - 3.2)/ 0.73
z_left
z_right <- ( 3.6 - 3.2 )/ 0.73
z_right
# use the pnorm functions
pnorm( z_right ) - pnorm( z_left )
#
#  or use the expanded pnorm function
pnorm( 3.6, mean=3.2, sd=0.73) - 
    pnorm( 2.8, mean=3.2, sd=0.73)


#########################
# For a N( 153, 14 ) distribution find
# P( X < 140 or X > 170)
#
# convert both values to z-scores
z_left <- ( 140 - 153 ) / 14
z_left
z_right <- ( 170 - 153 ) / 14
z_right
# use pnorm
pnorm( z_left) + (1-pnorm( z_right) )
#    or we coud do that as
pnorm( z_left ) + pnorm( z_right, lower.tail=FALSE)
#
# or we could use the expanded pnorm funtion
pnorm( 140, mean=153, sd=14) +
     ( 1 - pnorm( 170, mean=153, sd=14))
#  which we could have done as
pnorm( 140, mean=153, sd=14) +
     pnorm( 170, mean=153, sd=14, lower.tail=FALSE)


#
################### qnorm
#
# for a N(13.2,8.4) distribution 
# find the value of x such that
# P( X < x ) is 0.315
# for a N(0,1) the z value would be
z <- qnorm( 0.315 )
z
# so we convert that to our N(13.2,8.4)
# via
x <- z*8.4 + 13.2
x
#
# or we could use the expanded qnorm function
qnorm( 0.315, mean=13.2, sd=8.4 )

################################
#  for a N(4.3, 8.2) distribution
# find the value of x such  that 
#  P( X > x ) = 0.29
# for a N(0,1) the z value would be
z1 <- qnorm( 1 - 0.29 )
z1
#  which we could have found by 
z2 <- qnorm( 0.29, lower.tail=FALSE)
z2
# and then we need to move that value back 
# to our N( 4.3, 8.2)
x <- z1*8.2 + 4.3
x
# 
# or we could use the expanded qnorm as
qnorm( 1-0.29, mean=4.3, sd=8.2)
# or as
qnorm( 0.29, mean=4.3, sd=8.2, lower.tail=FALSE)