A Guide to dnorm, pnorm, rnorm, and qnorm in R

• Last Updated : 21 Apr, 2022

In this article, we will be looking at a guide to the dnorm, pnorm, qnorm, and rnorm methods of the normal distribution in the R programming language.

dnorm function

This function returns the value of the probability density function (pdf) of the normal distribution given a certain random variable x, a population mean μ, and the population standard deviation σ.

Syntax; dnorm(x, mean, sd)

Parameters:

• x: vector of quantiles.
• mean: vector of means.
• sd: vector standard deviation.

Example:

In this example, we will be finding the value of the standard normal distribution pdf at x=1 using the dnorm() function in the R.

R

 `dnorm``(x=1, mean=0, sd=1)`

Output:

`[1] 0.2419707`

pnorm function

This function returns the value of the cumulative density function (cdf) of the normal distribution given a certain random variable q, a population mean μ, and the population standard deviation σ.

Syntax: pnorm(q, mean, sd,lower.tail)

Parameters:

• q: It is a vector of quantiles.
• mean: vector of means.
• sd: vector standard deviation.
• lower.tail: It is logical; if TRUE (default), probabilities are otherwise

Example: In this example, we will be calculating the percentage of students at this school who are taller than 75 inches height of males at a certain school is normally distributed with a mean of μ=70 inches and a standard deviation of σ =3 inches using the pnorm() function in the R.

R

 `pnorm``(75, mean=70, sd=3, lower.tail=``FALSE``) `

Output:

`[1] 0.04779035`

At this school, 4.779% of males are taller than 75 inches.

qnorm function

This function returns the value of the inverse cumulative density function (cdf) of the normal distribution given a certain random variable p, a population mean μ, and the population standard deviation σ.

Syntax: qnorm(p, mean = 0, sd = 0, lower.tail = TRUE)

Parameters:

•  p: It represents the significance level to be used
• mean: vector of means.
• sd: vector standard deviation.
•  lower.tail = TRUE: Then the probability to the left of p in the normal distribution is returned.

Example:

In this example, we are calculating the Z-score of the 95th quantile of the standard normal distribution using the qnorm() function in R.

R

 `qnorm``(.95, mean=0, sd=1)`

Output:

`[1] 1.644854`

rnorm function

This function generates a vector of normally distributed random variables given a vector length n, a population mean μ and population standard deviation σ.

Syntax: rnorm(n, mean, sd)

Parameters:

• n: number of datasets to be simulated
• mean: vector of means.
• sd: vector standard deviation.

Example: In this example, with the use of the rnorm() function we are generating a vector of 10 normally distributed random variables with mean=10 and sd=2.

R

 `rnorm``(10, mean = 10, sd = 2) `

Output:

[1] 10.886837  9.678975 12.668778 10.391915  7.021026 10.697684  9.340888  6.896892 12.067081 11.049609

My Personal Notes arrow_drop_up
Related Articles