The corresponding r code
is given below.
theta <- seq(0,1, length = 10)
CD_theta <- function(x, p, n){
1 - pbinom(x, size = n, prob = p) + 1 / 2 * dbinom(x, size = n, prob = p)
}
Then I graphed the data as follows :
mytheta <- CD_theta(5, theta, 10)
df <- data.frame(theta = theta, mytheta = mytheta)
ggplot(df, aes(x = theta, y = mytheta)) +
geom_line(size = 1, col = "steelblue") +
ylab("H(Theta)") +
xlab("Theta")
The corresponding graph is given below.
As you can see there are two horizontal lines (graphed in red) and the two vertical lines (graphed in black). I need to find the two points on the x-axis corresponding to the intersections for a H(theta).
I used the locator()
function in r
to compute the two x intercepts for a single iteration. I would like iterate the above for 1000 times, so it is really tedious approach find them separately.
are there any other r
functions can be used find these two x intercept points?
Thank you in advance.
Here is a numerical approach using
optimize
function:Created on 2018-09-21 by the reprex package (v0.2.0).