[R] Obtaining the value of x at a given value of y in a smooth.spline object

Greg Snow Greg.Snow at imail.org
Thu Aug 13 02:51:56 CEST 2009


A few functions that may help are splinefun or approxfun along with uniroot.

________________________________________
From: Kavitha Venkatesan [kavitha.venkatesan at gmail.com]
Sent: Wednesday, August 12, 2009 3:43 PM
To: Greg Snow
Cc: r-help at r-project.org
Subject: Re: [R] Obtaining the value of x at a given value of y in a    smooth.spline object

I do want a programmatic solution. I was thinking of the linear
interpolation based on the 2 y-values bracketing the given y as well,
I think I will pursue this. Thanks a lot for your suggestion,

Kavitha

On Wed, Aug 12, 2009 at 4:25 PM, Greg Snow<Greg.Snow at imail.org> wrote:
> Part of the problem is that there could in theory be multiple x values that result in the same y value.
>
> One approach if you are happy with something interactive rather than programatical is to use the TkSpline function in the TeachingDemos package to fit the spline function and drag the x-value until you find the y value that you want.
>
> You can also look at the return from smooth.spline, find the y that is closest to your desired value and then find the corresponding x, or find the 2 y-values that bracket your choice and linearly interpolate the corresponding x values.
>
> Hope this helps,
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at imail.org
> 801.408.8111
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Kavitha Venkatesan
>> Sent: Wednesday, August 12, 2009 11:43 AM
>> To: r-help at r-project.org
>> Subject: [R] Obtaining the value of x at a given value of y in a
>> smooth.spline object
>>
>> I have some data fit to a smooth.spline object as follows: (x=vector of
>> data
>> for the predictor variable, y=vector of data for the response variable)
>>
>> fit <- smooth.spline(x,y)
>>
>> Now, given a spline fit point y_new, I want to be able to find out what
>> value of x_new yielded this fit value. How to do so?
>> (This problem is the inverse of the predict.smooth.spline function,
>> which
>> takes x_new as input and yields the corresponding y_new fit value)
>>
>> Any insight is much appreciated!
>>
>> Thanks,
>> Kavitha
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list