How to Use the Normal CDF in R (With Examples)

The Normal CDF (cumulative distribution function) is a function in R which is used to calculate the probability that a random variable falls within a given range of values. It uses the cumulative probability distribution of a given normal distribution to calculate the probability. It is used to calculate the area under the curve of a normal distribution. Examples of how to use the Normal CDF in R can be found in the R documentation.


You can use the following methods to work with the normal CDF (cumulative distribution function) in R:

Method 1: Calculate Normal CDF Probabilities

#calculate probability that random value is less than 1.96 in normal CDF
pnorm(1.96)

#calculate probability that random value is greater than 1.96 in normal CDF
pnorm(1.96, lower.tail=FALSE)

Method 2: Plot the Normal CDF

#define sequence of x-values
x <- seq(-4, 4, .01)

#calculate normal CDF probabilities
prob <- pnorm(x)
 
#plot normal CDF
plot(x, prob, type="l")

The following examples show how to use these methods in practice.

Example 1: Calculate Normal CDF Probabilities

The following code shows how to calculate the probability that a random variable takes on a value less than 1.96 in a standard normal distribution:

#calculate probability that random value is less than 1.96 in normal CDF
pnorm(1.96)

[1] 0.9750021

The probability that a random variables takes on a value less than 1.96 in a standard normal distribution is 0.975.

We can also find the probability that a random variable takes on a value greater than 1.96 by using the lower.tail argument:

#calculate probability that random value is greater than 1.96 in normal CDF
pnorm(1.96, lower.tail=FALSE)

[1] 0.0249979

And we can use the following syntax to find the probability that a random variable takes on a value between two values in a standard normal distribution:

#calculate probability that random value takes on value between -1.96 and 1.96
pnorm(1.96) - pnorm(-1.96)

[1] 0.9500042

The probability that a random variable takes on a value between -1.96 and 1.96 in a standard normal distribution is 0.95.

Example 2: Plot the Normal CDF

The following code shows how to plot a normal CDF:

#define sequence of x-values
x <- seq(-4, 4, .01)

#calculate normal CDF probabilities
prob <- pnorm(x)
 
#plot normal CDF
plot(x, prob, type="l")

normal CDF plot in R

The x-axis shows the values of a random variable that follows a standard normal distribution and the y-axis shows the probability that a random variable takes on a value less than the value shown on the x-axis.

For example, if we look at x = 1.96 then we’ll see that the cumulative probability that x is less than 1.96 is roughly 0.975:

Note that you can modify the aesthetics of the normal CDF plot as well:

#define sequence of x-values
x <- seq(-4, 4, .01)

#calculate normal CDF probabilities
prob <- pnorm(x)
 
#plot normal CDF
plot(x, prob, type='l', col='blue', lwd=2, main='Normal CDF', ylab='Cumulative Prob')

Related: 

The following tutorials explain how to perform other common operations in R:

x