I have two ecdf plots using below code:
ecdf1 <- ecdf(data1)
ecdf2 <- ecdf(data2)
These plots are crossing each other. I need to take the crossing point (intersection point) coordinates. How should I do this in R?
I have two ecdf plots using below code:
ecdf1 <- ecdf(data1)
ecdf2 <- ecdf(data2)
These plots are crossing each other. I need to take the crossing point (intersection point) coordinates. How should I do this in R?
Copyright © 2021 Jogjafile Inc.
Lets' create a reproducible example to demonstrate:
Now we use your code to create the two ecdf functions:
If we plot them, we will see these curves intersect at two points: once between 0 and 1, and again just above 2.
To find these exact points, we create a function of x that is the difference between the two ecdf functions at x. We then use the function
unirootto determine where this difference function is equal to 0:We can check our results make sense:
And even plot segments to demonstrate the intersections are correct:
Created on 2023-02-26 with reprex v2.0.2