[Rd] splinefun gives incorrect derivs when extrapolating to the left (PR#13132)

Berwin A Turlach berwin at maths.uwa.edu.au
Tue Oct 7 13:48:27 CEST 2008


On Tue, 7 Oct 2008 19:31:03 +0800
Berwin A Turlach <berwin at maths.uwa.edu.au> wrote:

> The attached patch (against the current SVN version of R) implements
> the latter strategy.  With this patch applied, "make check
> FORCE=FORCE" passes on my machine.  The version of R that is build
> seems to give the correct answer in your example:

Perhaps I should have thought a bit more about this.  For a natural
spline c[1] is zero, and d[1] is typically not but for evaluations
left of the first knot it should be taken as zero.  So the attached
patch solves the problem in what some might consider a more elegant
manner. :)

With the patch "make check FORCE=FORCE" works on my machine and it
also solves your example:

R> x <- 1:10
R> y <- sin(x)
R> 
R> splfun <- splinefun(x,y, method='natural')
R> 
R> # these should be linear (and are)
R> splfun( seq(0,1, 0.1) )  
 [1] 0.5682923 0.5956102 0.6229280 0.6502459 0.6775638 0.7048816
 [7] 0.7321995 0.7595174 0.7868352 0.8141531 0.8414710
R> 
R> # these should all be the same
R> splfun( seq(0,1, 0.1), deriv=1 )  
 [1] 0.2731787 0.2731787 0.2731787 0.2731787 0.2731787 0.2731787
 [7] 0.2731787 0.2731787 0.2731787 0.2731787 0.2731787
R> 
R> # these should all be 0
R> splfun( seq(0,1, 0.1), deriv=2 )
 [1] 0 0 0 0 0 0 0 0 0 0 0
R> splfun( seq(0,1, 0.1), deriv=3 )  
 [1] 0 0 0 0 0 0 0 0 0 0 0

HTH.

Cheers,
	
	Berwin

=========================== Full address =============================
Berwin A Turlach                            Tel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability        +65 6516 6650 (self)
Faculty of Science                          FAX : +65 6872 3919       
National University of Singapore     
6 Science Drive 2, Blk S16, Level 7          e-mail: statba at nus.edu.sg
Singapore 117546                    http://www.stat.nus.edu.sg/~statba
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: R-patch1
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20081007/b68ce66d/attachment.pl>


More information about the R-devel mailing list