I have 2 distributions - 1 beta and 1 normal and I need to find the intersection of their pdfs. I know the parameters for both and am able to visually see the intersection, but am looking for a way for R to calculate the exact point. Anybody have an idea of how to do this?
Use uniroot()
.
uniroot(function(x) dbeta(x, 1, 2)-dnorm(x, 0, 1), c(0, 1))
## $root
## [1] 0.862456
##
## $f.root
## [1] 5.220165e-05
##
## $iter
## [1] 3
##
## $estim.prec
## [1] 6.103516e-05
This solves an equation dbeta(x, ...) == dnorm(x, ...)
w.r.t. x
(in the inverval [0,1], as this is the support of a beta distribution), i.e. finds the root of dbeta(x, ...) - dnorm(x, ...)
. The resulting list's root
field gives you the answer (more or less precisely).