Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

point of intersection 2 normal curves

Although I think this is a basic question, I can't seem to find out how to calculate this in R:

the point of intersection (I need the x-value) of 2 or more normal distributions (fitted on a histogram) which have for example the following parameters:

d=data.frame(mod=c(1,2),mean=c(14,16),sd=c(0.9,0.6),prop=c(0.6,0.4))

With the mean and standard deviation of my 2 curves, and prop the proportions of contribution of each mod to the distribution.

like image 603
Wave Avatar asked Jun 07 '13 10:06

Wave


1 Answers

You can use uniroot:

f <- function(x) dnorm(x, m=14, sd=0.9) * .6 - dnorm(x, m=16, sd=0.6) * .4

uniroot(f, interval=c(12, 16))

$root
[1] 15.19999

$f.root
[1] 2.557858e-06

$iter
[1] 5

$estim.prec
[1] 6.103516e-05


ETA some exposition:

uniroot is a univariate root finder, ie given a function f of one variable x, it finds the value of x that solves the equation f(x) = 0.

To use it, you supply the function f, along with an interval within which the solution value is assumed to lie. In this case, f is just the difference between the two densities; the point where they intersect will be where f is zero. I got the interval (12, 16) in this example by making a plot and seeing that they intersected around x=15.

like image 83
Hong Ooi Avatar answered Sep 28 '22 03:09

Hong Ooi