[R] Derivative of nonparametric curve

spencerg spencer.graves at prodsyse.com
Wed Sep 9 16:08:43 CEST 2009


      This may be overkill for your application, but you might be 
interested in the "fda" package, for which a new book appeared a couple 
of months ago:  "Functional Data Analysis with R and Matlab" (Springer 
Use R! series, by Ramsay, Hooker and Graves;  I'm the third author).  
The package includes a "scripts" subdirectory with R code to recreate 
all but one of the 76 figures in the book.  [To find this "scripts" 
directory, use "system.file('scripts', package='fda')".] 


      Functional data analysis generalizes spline smoothing in two 
important ways: 


           (1) It supports the use of an arbitrary finite basis set to 
approximate elements of a function space;  spline smoothing uses splines 
only, usually cubic splines.  The first derivative of a cubic spline is 
piecewise quadratic, and the second derivative is piecewise linear.  If 
you want something smoother than linear, you need at least a quartic 
spline, and Ramsay has recommended quintics -- degree 5 polynomials = 
order 6 spline. 


           (2) It allows the curve to be smoothed using an arbitrary 
linear differential operator, not just the second derivative.  This can 
be important if you have theory saying that the "truth" should follow a 
particular differential equation.  Otherwise, if you want to estimate 
the second derivative, Ramsay has recommended smoothing with the fourth 
derivative rather than the second.  (In any event, smoothing is achieved 
by penalized least squares with the penalty being proportional to the 
integral of the square of the chosen linear differential operator.) 


      To reinforce this second point, chapter 11 of "Functional Data 
Analysis with R and Matlab" describes "functional differential 
analysis", which will estimate non-constant coefficients in a 
differential equation model. 


      Hope this helps. 
      Spencer Graves


Liaw, Andy wrote:
> From: Rolf Turner
>   
>> On 8/09/2009, at 9:07 PM, FMH wrote:
>>
>>     
>>> Dear All,
>>>
>>> I'm looking for a way on computing the derivative of first and  
>>> second order of a smoothing curve produced by a nonprametric  
>>> regression. For instance, if we run the R script below, a smooth  
>>> nonparametric regression curve is produced.
>>>
>>> provide.data(trawl)
>>> Zone92   <- (Year == 0 & Zone == 1)
>>> Position <- cbind(Longitude - 143, Latitude)
>>> dimnames(Position)[[2]][1] <- "Longitude - 143"
>>> sm.regression(Longitude, Score1, method = "aicc", col = "red",   
>>> model = "linear")
>>>
>>> Could someone please give some hints on the way to find the  
>>> derivative on the curve at some points ?
>>>       
>> See
>>
>> 	?smooth.spline
>> and
>> 	?predict.smooth.spline
>>     
>
> Since sm.regression() (from the sm package, I presume) uses kernel
> methods, a kernel-based estimator of derivatives is available in the
> KernSmooth package.
>
> Andy
>  
>   
>> 	cheers,
>>
>> 		Rolf Turner
>>
>> ######################################################################
>> Attention:\ This e-mail message is privileged and 
>> confid...{{dropped:9}}
>>
>> ______________________________________________
>> 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.
>>
>>     
> Notice:  This e-mail message, together with any attachme...{{dropped:12}}
>
> ______________________________________________
> 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.
>
>   


-- 
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567




More information about the R-help mailing list