The normal distribution in R is categorized as rnorm, dnorm, and pnorm. A normal distribution, also known as a Gaussian distribution, is a symmetrical distribution of continuous data with a bell-shaped curve. The normal distribution is widely used in statistical analysis to model the distribution of various data types.
The rnorm, dnorm, and pnorm functions in R help us calculate the normal density, distribution, and quantile function for a set of values.
pnorm in R
The pnorm() in R is a built-in mathematical function that returns the Cumulative Density Function (CDF) value of the normal distribution given a specific random variable q, the population mean μ, and the population standard deviation σ.
The pnorm() function takes several parameters as input, including the normal distribution’s mean, standard deviation, and quantile. It returns the cumulative probability of the normal distribution for the given parameters.
The pnorm() function calculates the c. d. f. where X is normal. Optional arguments described in the online documentation specify the parameters of the particular normal distribution.
pnorm(q, mean, sd, lower.tail = TRUE, log.p = FALSE)
q: It is a vector of quantiles.
mean: It is a vector of means.
sd: It is a vector of standard deviations.
lower.tail: It is logical; if TRUE (default), probabilities are otherwise.
log, log.p: It is a logical argument.
Find the percentage of males taller than 78 inches in a population with mean = 74 and sd = 2.
pnorm(78, mean = 74, sd = 2, lower.tail = FALSE)
Find the percentage of otters that weight less than 33 lbs in a population with mean = 40 and sd = 8. Let’s see the following code example.
pnorm(33, mean=40, sd = 8)
The pnorm() function returns the integral from −∞ to q of the normal distribution pdf, where q is a Z-score. Try to guess the value of pnorm(0).
The pnorm() function also takes the argument lower.tail. If the lower.tail is set equal to FALSE, then pnorm returns the integral from q to ∞ the pdf of the normal distribution.
Use the pnorm() function to calculate the probability density of a normal distribution by setting the lower.tail argument to FALSE.
Note that pnorm(q) is the same as 1-pnorm(q, lower.tail = FALSE).
How to calculate cumulative distribution of normal distribution in R
To calculate the cumulative distribution of a normal distribution in R, use the pnorm() function and pass the lower.tail argument to TRUE.
pnorm(1, mean = 0, sd = 1, lower.tail = TRUE)
In the above code, it returns the cumulative distribution of the normal distribution with mean 0 and standard deviation 1 at the value 1.
The pnorm() function has an optional argument called log.p, which is set to FALSE by default. If set to TRUE, the pnorm() function returns the logarithm of the probability density or cumulative distribution.
# Import the stats package library(stats) # Calculate the cumulative probability of a normal distribution with a mean of 0, # a standard deviation of 1, and a quantile of 0.5 prob <- pnorm(q = 0.5, mean = 0, sd = 1) # Print the cumulative probability print(prob)
We first imported the stats package in the above code.
In the next step, we use the pnorm() function to calculate the cumulative probability of a normal distribution with a mean of 0, a standard deviation of 1, and a quantile of 0.5.
The pnorm() function returns the cumulative probability of the normal distribution as a numeric value, which we store in the prob variable.
At last, we used the print() function to print the prob variable, which displays the cumulative probability of the normal distribution.
Applications of the pnorm() function in R
- The pnorm() function is mostly used in statistical analysis, particularly when you need to model the distribution of continuous data.
- The pnorm() function allows you to calculate the probability density or cumulative distribution of normal distribution at specific values, which can help you make predictions about the likelihood of certain events occurring.
- Calculating the probability of obtaining the specific test statistic or sample mean under the premise that the NULL hypothesis is TRUE. The pnorm() function helps to determine if the observed result is statistically significant.
Using the pnorm() function, we can calculate the cumulative probability of a normal distribution in R.
Krunal Lathiya is a Software Engineer with over eight years of experience. He has developed a strong foundation in computer science principles and a passion for problem-solving. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language.