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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With