[R] [FORGED] Spline function
Rolf Turner
r@turner @end|ng |rom @uck|@nd@@c@nz
Wed Aug 15 00:40:58 CEST 2018
On 15/08/18 03:48, Tania Morgado Garcia wrote:
> Hello everyone. I'm new to R and I'm using spline functions. With the
> command splinefun (x, y) I get the function of interpolating the values x
> and y. Later, I can evaluate that function for values of x by obtaining the
> respective values of y. The point is that I need the inverse operation,
> with the function, for a value of Y I need to know the value of x. Could
> you please help me?
Your question is ill-posed. There could easily be multiple x values
corresponding to a single y value, unless the spline function is monotone.
If you can specify an interval which encloses the x value that you are
trying to and over which the spline function is monotone, then uniroot()
might provide what you want.
Something like:
spf <- splinefun(x,y)
uniroot(f=function(x){spf-y0},interval=c(a,b))
where y0 is the y value for which you want the corresponding x value,
where spf() is monotone on [a,b], and where there *exists* an x value
between a and b such that spf(x) = y0.
Good luck.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list