From njs at pobox.com  Wed Aug  1 17:36:02 2012
From: njs at pobox.com (Nathaniel Smith)
Date: Wed, 1 Aug 2012 16:36:02 +0100
Subject: [Rd] Numerics behind splineDesign
In-Reply-To: <D7CCBAE0-4D80-436D-8594-17EDF691A75A@gmail.com>
References: <CAPJVwB=ppJ=SOs9k0p5ZHqGdnk8L1MZMBUbCSQ6oH5Zd5Pwpig@mail.gmail.com>
	<loom.20120731T152127-870@post.gmane.org>
	<CACk-te3ERmEVe2f2YqU8t5iFSVj0E9a4RGDTudDvGiAUyUQUtg@mail.gmail.com>
	<D7CCBAE0-4D80-436D-8594-17EDF691A75A@gmail.com>
Message-ID: <CAPJVwBnB6-=V7PMejU0qe9WG1YLn1d3gDGFQd-timyYEwkdZkQ@mail.gmail.com>

Thanks everyone for the suggestions.

On Wed, Aug 1, 2012 at 2:39 PM, peter dalgaard <pdalgd at gmail.com> wrote:
>
> On Jul 31, 2012, at 15:46 , Bert Gunter wrote:
>
>> Well, I would first check the references given in the Help file!.
>> That's what they're for, no?  Hastie's book is likely to more complete
>> on the algebra, I think.

How embarrassing... the help files do cite the white book (only), and
I did check it of course, but it has no more details on how the basis
functions are computed than does the help file itself, and so I must
have forgotten about it when writing my email. Still, my apologies for
the confusion.

I'm not sure what you mean by "Hastie's book", though?

>> You might also be interested in the relevant chapters of Friedman,
>> Hastie, et. al "The Elements of Statistical Learning Theory," which
>> might be a gentler exposition of the math.
>>
>> Of course, the code (or a suitable exposition of it, which may not
>> exist) is the ultimate reference.
>
> Also check out the various web resources (Google for basis spline or B-spline). I don't recall the white book chapter, but it might be a little short on the algebraic details. Another Google point is "de Boor".

And indeed, it looks like the appendix to chapter 5 of Hastie,
Tibshirani, and Friedman (2008) has a short description of the de Boor
algorithm. Excellent. For the archives, this seems to be enough to
exactly implement spline.des/splineDesign, and if anyone else is
working in Python then it turns out that there is a more-or-less
undocumented implementation of this algorithm in
scipy.interpolate.splev.

Now I just have to grovel over the R code in ns() and bs() to figure
out how exactly they pick knots and handle boundary conditions, plus
there is some code that I don't understand in ns() that uses qr() to
postprocess the output from spline.des. I assume this is involved
somehow in imposing the boundary conditions...

Thanks again everyone for your help,
-- Nathaniel



[Rd] Numerics behind splineDesign
Nathaniel Smith