Re: [R] Spline function

2018-08-14 Thread Duncan Murdoch

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Spline function

2018-08-14 Thread Greg Snow
The uniroot function can be used to find a value in a specified
interval, if it exists.
On Tue, Aug 14, 2018 at 3:30 PM 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?
> A cordial greeting
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Spline function

2018-08-14 Thread Bert Gunter
If I understand correctly, not in general possible.

Suppose for a bunch of different x's the y's are all constant =0. What x
would correspond to y = 1.

Or suppose (x,y) pairs trace a sine function over several periods. Then
there is no unique x corresponding to y = .5, say.

Perhaps if you more explicitly specified the nature of your problem (e.g.
is y monotonic in x?) some assistance might be provided.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Tue, Aug 14, 2018 at 8: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?
> A cordial greeting
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Spline function

2018-08-14 Thread Tania Morgado Garcia
 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?
A cordial greeting

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Spline Function

2011-05-20 Thread Animesh Saxena
I am using R for volatility calibration (Variance Gamma distribution). 
My question is very basic and not at all related to mathematics!


y=spline(KK,CallPrices,,fmm,,,strikes)

When calling spline function it returns a list y

The list contains some numbers which I have to subtract from another 
array called MarketPrices


since y is a list a normal subtraction is not possible.

For example I get this output from spline function...

$x
 [1] 1050 1100 1150 1175 1200 1250 1300 1350 1400 1450 1500

$y
 [1] 175.15474 146.78475 121.76502 110.50149 100.05049  81.49610  
65.87413  52.89799  42.24847  33.59852  26.63327


I can chunk out...the second list...using modelprices[2]

 modelprices[2]
$y
 [1] 175.15474 146.78475 121.76502 110.50149 100.05049  81.49610  
65.87413  52.89799  42.24847  33.59852  26.63327


Still its a list and I think I need an array
other array is
 marketprices
 [1] 171.4 140.4 112.8  99.8  88.2  66.9  49.5  35.7  25.2  17.0  12.2
 marketprices-modelprices[2]
Error in marketprices - modelprices[2] :
  non-numeric argument to binary operator

Is there any way to perform this substraction?

I tried the normal approaches like
 as.numeric(modelprices[2])
Error: (list) object cannot be coerced to type 'double'

Thanks in advance!--

Regards,
Animesh Saxena

(www.quantanalysis.in)

__
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.