[R] How to generate natural cubic spline in R?

Martin Maechler maechler at stat.math.ethz.ch
Wed Apr 1 10:23:36 CEST 2009


>>>>> "SK" == Stephan Kolassa <Stephan.Kolassa at gmx.de>
>>>>>     on Tue, 31 Mar 2009 22:20:50 +0200 writes:

    SK> Hi David,
    SK> David Winsemius schrieb:
    >> The splinefun documentation indicates that "natural" is one of the types 
    >> of cubic spline options available.

    SK> That sounds good, didn't know that... rcs() has the advantage of coming 
    SK> with a book (Harrell's "Regression Modeling Strategies").

well,  and  splinefun() comes with R !!!

    >> Does rcs actually do fitting? Such would not be my expectation on 
    >> reading the documentation and I do not see any examples of such 
    >> functionality in the help pages.

    SK> Nope, but you can include rcs() within fitting functions, 
    SK> lm(foo~rcs(bar,3)), which makes more sense to me than having a spline 
    SK> function fit... Looks like better encapsulation to me.

well,  but  ns()  has been part of the S language for ages, and
part of R since its very early days,
exactly for the purpose to be used in something like  
	lm(y ~ ns(.) + ..)

So while rcs() may have extra merits, (I assume it does, as I
assume Frank Harrell will have known about ns()),
in order to solve the OP's problem, I still believe that
"standard R" [and "good old S version 3 for that matter]
contains all functionality needed.

Martin Maechler, ETH Zurich

    SK> Best,
    SK> Stephan

    SK> ______________________________________________
    SK> R-help at r-project.org mailing list
    SK> https://stat.ethz.ch/mailman/listinfo/r-help
    SK> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    SK> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list