Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integral of dnorm(x, mean=200, sd=20) is not 1

I tried to calculate the integral of the density of the normal distribution with expected value 200 and standard deviation 20. From -Inf to Inf this should be 1.

I get the following:

> integrate(dnorm, mean=200, sd=20,-Inf, Inf)$value
[1] 1.429508e-08

For expected values below 169 I get the right value, 1. How can I get the right value for bigger expected values?

like image 694
Juli Schmitt Avatar asked Oct 18 '25 21:10

Juli Schmitt


1 Answers

Alternatively

integrate(dnorm, mean=200, sd=20, lower= -Inf, upper= Inf, abs.tol = 0)$value
[1] 1

See here.

And to see what is going on, note the number of subdivisions in the following:

js <- integrate(dnorm, mean=200, sd=20, lower = -Inf, upper = Inf)
as <- integrate(dnorm, mean=200, sd=20, lower = -1e4, upper = 1e4)
cj <- integrate(dnorm, mean=200, sd=20, lower = -Inf, upper = Inf, abs.tol = 0)

str(js)
List of 5
 $ value       : num 1.43e-08
 $ abs.error   : num 2.77e-08
 $ subdivisions: int 2
 $ message     : chr "OK"
 $ call        : language integrate(f = dnorm, lower = -Inf, upper = Inf, mean = 200, sd = 20)
 - attr(*, "class")= chr "integrate"

str(as)
List of 5
 $ value       : num 1
 $ abs.error   : num 2e-07
 $ subdivisions: int 9
 $ message     : chr "OK"
 $ call        : language integrate(f = dnorm, lower = -10000, upper = 10000, mean = 200,      sd = 20)
 - attr(*, "class")= chr "integrate"

str(cj)
List of 5
 $ value       : num 1
 $ abs.error   : num 9.37e-05
 $ subdivisions: int 12
 $ message     : chr "OK"
 $ call        : language integrate(f = dnorm, lower = -Inf, upper = Inf, mean = 200, sd = 20,      abs.tol = 0)
 - attr(*, "class")= chr "integrate"
like image 79
coffeinjunky Avatar answered Oct 21 '25 11:10

coffeinjunky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!