[R] predict(backSpline(x)): losing my marbles?

Ben Bolker bbolker at gmail.com
Tue Sep 14 18:15:22 CEST 2010


  I'm sure I'm doing something completely boneheaded here, but I've
used this idiom
(constructing an interpolation spline and using prediction from a
backSpline to find
an approximation profile confidence interval) many times before and
haven't hit this
particular problem:

  r2 <- c(1.04409027570601, 1.09953936543359, 1.15498845516117,
1.21043754488875,
          1.26588663461633, 1.32133572434391, 1.37678481407149,
1.43223390379907,
          1.48768299352664, 1.54313208325422, 1.5985811729818,
1.65403026270938,
          1.70947935243696, 1.76492844216454, 1.82037753189212,
1.87582662161970,
          1.93127571134727, 1.98672480107485, 2.04217389080243,
2.09762298053001
          )
  d2 <- c(6.1610616585333, 5.70079375491741, 5.2366151167289,
4.77263065800071,
          4.31310259797181, 3.86232922249189, 3.42452047126494,
3.00367670365119,
          2.6034766331926, 2.22717964214416, 1.87754657382891,
1.55678176465949,
          1.26649764837839, 1.00770187223770, 0.780805622450771,
0.585650849661306,
          0.421553364080296, 0.287358347766713, 0.18150469048976,
0.102094654969619
          )
  plot(d2,r2,type="b")
  require(splines)
  sp <- interpSpline(r2,d2)
  psp <- predict(sp)
  points(psp$y,psp$x,col=5)
  bsp <- backSpline(sp)
  lines(predict(bsp,seq(0,6,length=101)),col=2)

   The prediction from the spline (cyan dots) looks perfectly reasonable.
The prediction from the inverted spline matches the curve over part of
the range but
goes crazy elsewhere.  I would have expected it to be reasonably close
to this well-behaved
curve over the whole range.

  I have looked at the docs for interpSpline, backSpline,
predict.bSpline, ... and nothing jumps out at me.

   Please be gentle, if possible, in explaining to me what I'm missing ...

  thanks,
    Ben Bolker



More information about the R-help mailing list