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.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Kavitha Venkatesan > Sent: Wednesday, August 12, 2009 11:43 AM > To: r-help@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@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. ______________________________________________ R-help@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.