re: Cubic splines in package "mgcv" I don't have access to Gu (2002) but clearly the function R(x,z) defined on p126 of Simon Wood's book is piecewise quartic, not piecewise cubic.
Like Kunio Takezawa (below) I was puzzled by the word "cubic" on p126. As Simon Wood writes, this basis is not actually used by mgcv when specifying bs="cr". Maybe the point is that at the knot, this continuous function has continuous 1st and 2nd derivatives, but a discontinuous 3rd derivative, so in that sense it behaves like a cubic spline. Greg #using the code from p127 of Wood: #compare Wood Fig 3.4 (p125) #if the function were piecewise cubic the 3rd derivative would be piecewise constant rk<-function(x,z) { ((z-0.5)^2-1/12)*((x-0.5)^2-1/12)/4-((abs(x-z)-0.5)^4-(abs(x-z)-0.5)^2/2+7/240)/24 } par(mfrow=c(2,2)) u<-seq(0,1,by=0.001) plot(u,rk(u,5/6),main="function") plot(u[-1],1e3*diff(rk(u,5/6),differences=1),main="1st derivative") plot(u[-(1:2)],1e6*diff(rk(u,5/6),differences=2),main="2nd derivative") plot(u[-(1:3)],1e9*diff(rk(u,5/6),differences=3),main="3rd derivative") par(mfrow=c(1,1)) ------- From: Simon Wood <s.wood> Date: Sun, 6 Jan 2008 16:59:35 +0000 On Wednesday 26 December 2007 04:14, Kunio takezawa wrote: > R-users > E-mail: r-help at r-project.org > My understanding is that package "mgcv" is based on > "Generalized Additive Models: An Introduction with R (by Simon N. Wood)". > On the page 126 of this book, eq(3.4) looks a quartic equation with respect > to > "x", not a cubic equation. I am wondering if all routines which uses > cubic splines in mgcv are based on this quartic equation. --- No, `mgcv' does not use the basis given on page 126. See sections 4.1.2-4.1.8 of the same book for the bases used. > In my humble opinion, the '^4' in the first term > of the second line of this equation should be '^3'. --- Perhaps take a look at section 2.3.3 of Gu (2002) "Smoothing Spline ANOVA" for a bit more detail on this/ > > K. Takezawa -- > Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283 ______________________________________________ R-help@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.