[Rd] obscure error message from splines::ns

Ben Bolker bbolker at gmail.com
Sat May 14 14:46:17 CEST 2011


  In the following case,


library(splines)
tt <- c(55, 251, 380, 289, 210, 385, 361, 669)
nn <- rep(0:7,tt)
ns(nn,4)
## knots are located at (0.25,0.5,0.75); quantiles = (2,5,7)

  we get the error

Error in qr.default(t(const)) :
  NA/NaN/Inf in foreign function call (arg 1)

  because the 75th quantile (the location of the last "interior" knot)
ends up on the boundary.  As a result, the call to
spline.des(...)$design within the bs() function call returns a design
matrix that includes NaN values, which triggers the error when qr() is
called.

(This alternative works OK:
ns(nn,4,knots=seq(min(nn),max(nn),length=5)[2:4])
)

   This could be argued to be a "well, just don't do that" case: splines
are designed for continuous data where this wouldn't happen.  On the
other hand, this was encountered as part of a sensible (IMO) data
analysis strategy, and it would be nice if there were at least an
informative warning message.  If there were any enthusiasm for it, I
would try to come up with a test and warning to incorporate into the
current version of bs() ...

  Ben Bolker



More information about the R-devel mailing list