[R] Spline function
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Wed Aug 15 01:35:08 CEST 2018
On 14/08/2018 11:48 AM, 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?
Others have pointed out uniroot(). One other possibility: maybe you
don't need both the function and its inverse, or an approximate inverse
is good enough. In either of those cases, just swap x and y in the call
to splinefun(), and you'll get a new function mapping y values to the
corresponding x values. (You'll get nonsense or an error in cases where
this mapping is not unique.) It won't match the inverse of the original
spline interpolator except at observed (x,y) pairs, but will usually be
close, especially if the functions are pretty smooth.
Duncan Murdoch
More information about the R-help
mailing list