23.6 C
London
Friday, July 25, 2025
HomeRProbability Distributions in RHow to Use the Normal CDF in R (With Examples)

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

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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 #calculate normal CDF probabilities
prob #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 #calculate normal CDF probabilities
prob #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 #calculate normal CDF probabilities
prob #plot normal CDF
plot(x, prob, type='l', col='blue', lwd=2, main='Normal CDF', ylab='Cumulative Prob')

Related: How to Use seq Function in R

Additional Resources

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

How to Plot a Normal Distribution in R
How to Calculate Z-Scores in R
A Guide to dnorm, pnorm, qnorm, and rnorm in R

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories