2

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?

1 Answers1

5

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).

gagolews
  • 12,836
  • 2
  • 50
  • 75
  • Thanks for your response! This may be a dumb question, but am I supposed to input something for x? I tried your code above using my parameters and I got an answer of 2.710505e-20 when I was expecting something around .6. Is it possible that there are multiple intersections and this just gives the first one? – user2989290 Apr 30 '14 at 19:31
  • `2.71e020` is practically equal to 0. What are your parameters? If you are sure that it's sth around .6 you may wish to look for the solution e.g. in the interval [0.5,0.7]. BTW, `x` is OK, it's a variable with respect to which the solution is searched. – gagolews Apr 30 '14 at 20:26
  • Yep, I just had to change the interval from c(0,1) to c(.2,.8) and got an answer of .58. Thanks for your help! – user2989290 Apr 30 '14 at 20:39