[R] find inflexion point of discrete value list with R

Jonas Stein news at jonasstein.de
Fri Jan 13 11:09:09 CET 2012


>>>  d2y <- diff(dy)
>>>  which(dy==0)  ## critical values
>>>  sign(s2y)[which(dy==0)]  ## test for max/min/saddle
>>>  which(d2y==0)   ## inflection points
>> 
>> I would think that testing for d2y==0 would be akin to the error in
>> numeric analysis warned about in FAQ 7.31. Seems unlikely that in real
>> data that there would always be three points in a row with equal
>> differences at a "true" inflection and even then, many of the ones you
>> did find satisfying that criterion would not be in fact inflection
>> points. Wouldn't it be better to fit a spline and then do your testing
>> on the spline approximation?
>> 
>> Counter-example:
>>  x=1:10
>>> y=c(1,2,3,5,7,10,13,16,20,24)
>>>  dy <- diff(y)
>>>  d2y <- diff(dy)
>>> which(d2y==0)
>> [1] 1 3 5 6 8
>> 
>> And actually the original data was a pretty good counter-example as well.
>
>
>   The original post wasn't entirely clear, but I thought the data were
> indeed integers and that the discrete-state version of
> min/max/inflection point was indeed what was wanted.  Yes, if the
> underlying variable is continuous you might want to use splinefun(),
> with its deriv= argument, and uniroot(), to find maxima and minima.
> Might be a little tricky in general, although with an interpolation
> spline between a finite set of points you can at least deal with it
> exhaustively.

my real data is not limited to integer. Do you know a ready to use code
example for this?

Would it be a good idea to create a function and make it public to the
community? And if yes as single .R file, or as a library?

kind regards,

-- 
Jonas Stein <news at jonasstein.de>



More information about the R-help mailing list