0

I was wondering why I can't find the other existing value of x whose f(x) equals the f(.6)?

In other words, I'm wondering how to find the x value of the point indicated by the red X in the picture below?

Here is what I have tried without success:

source("https://raw.githubusercontent.com/rnorouzian/i/master/ii.r") # source the function

f <- function(x, n.pred = 5, N = 100, conf.level = .95){ 
  ci <- R2.ci(R2 = x, n.pred = n.pred, N = N, conf.level = conf.level)  # The objective function
  ci$upper - ci$lower
}

curve(f, panel.f = abline(v = .6, h = f(.6), col = 2, lty = c(2, 1)))  # curve the function

uniroot(function(x) f(.6) - f(x), c(0, 1))[[1]]  # find the requested 'x' value

`Error: f() values at end points not of opposite sign`

enter image description here

rnorouzian
  • 7,397
  • 5
  • 27
  • 72
  • are you looking for [this?](https://stackoverflow.com/questions/50087814/how-to-find-an-intersection-of-curve-and-circle/50089155#50089155) – Onyambu Jul 14 '18 at 00:15
  • 1
    I cant run your code. That is why I directed you to that – Onyambu Jul 14 '18 at 00:19
  • uniroot just returns one root. and you need be on both side of the intersection with that function. Rather than using `c(0,1)` as the range, run it writce with `c(0,.5)` and `c(.5,1)` – MrFlick Jul 14 '18 at 00:19
  • `Error in peta2F(peta, df1, df2) : could not find function "peta2F" ` – Onyambu Jul 14 '18 at 00:20
  • Am sorry still experiencing the same error – Onyambu Jul 14 '18 at 00:24
  • still more errors:`Error in peta2ncp(P.eta.sq, N) : could not find function "peta2ncp"` – Onyambu Jul 14 '18 at 00:27
  • What's to say there are only two? "Find every intersection of arbitrary functions" isn't really a well defined mathematical numeric optimization problem. Maybe you want an analytic solution instead, but R is not going to help much there. – MrFlick Jul 14 '18 at 00:36
  • if you are using uniroot then the interval should be c(0,0.4) will give you the answer – Onyambu Jul 14 '18 at 00:36
  • Maybe this question would help: https://stackoverflow.com/questions/20519431/finding-point-of-intersection-in-r – MrFlick Jul 14 '18 at 00:36

1 Answers1

0
 abline(v=uniroot(function(x) f(.6) - f(x), c(0, 0.4))[[1]])

enter image description here

Onyambu
  • 67,392
  • 3
  • 24
  • 53