How can I get the normalizing constant from a non-standard distribution. Ex:
x <- c(rnorm(500,10,1),rnorm(500,20,2),rnorm(500,35,1))
after using density in R
dens<-density(x,n=length(x),adjust=0.4)
How can I get the normalizing constant from a non-standard distribution. Ex:
x <- c(rnorm(500,10,1),rnorm(500,20,2),rnorm(500,35,1))
after using density in R
dens<-density(x,n=length(x),adjust=0.4)
Copyright © 2021 Jogjafile Inc.
The result of density() should be a proper probability density function, so the area under the curve returned by density() should already be 1.
Your example:
We can get an approximation of the area under the pdf by numerically integrating it:
Which gives
The area is indeed rather close to 1.
There are numerical accuracy issues however which may cause this area to deviate significantly from 1. They are discussed here for example.