Solved – rnorm vs dnorm in R

distributionsnormal distributionr

In human language the rnorm(n=1000, m=24.2, sd=2.2) returns the random numbers which follows normal distribution. Another explanation could be that it returns random numbers from which the histogram can be created. If you draw normal (bell shaped) curve it will perfectly fits to this histogram. Can you please explain dnorm in such human language (or even with math and/or graphic but to be understandable by newbie)?

Best Answer

You know the probability density function for a standard normal distribution is

$\frac{1}{\sqrt{2\pi}}e^\frac{-x^2}{2} $.

The dnorm() function is just used to calculate the value of this function.

You can test using the following R code

density_standard_norm <- function(x)
{
1/sqrt(2*pi)*exp(-0.5*x^2)
}

dnorm(1, mean = 0, sd = 1)
[1] 0.2419707
density_standard_norm(1)
[1] 0.2419707

dnorm(2, mean = 0, sd = 1)

[1] 0.05399097

density_standard_norm(2) 
[1] 0.05399097

They are equal. For non-standard normal it's same.

Related Question