[R] stats:: spline's method could not be monoH.FC

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Sat May 2 18:43:11 CEST 2020


>>>>> Abby Spurdle 
>>>>>     on Fri, 1 May 2020 17:21:32 +1200 writes:

    > I agree, the documentation gives the impression that stats::spline
    > would allow "monoH.FC".

You are right, this is a lapsus,  thank you for reporting it!

    > My guess is that stats::spline doesn't allow it because the function
    > is designed to return a list with x and y components. This doesn't
    > suit monotonic cubic Hermite splines because the function would also
    > need to return the slopes. Furthermore, additional functions may (or
    > may not) be required depending on what you want to do with x, y and
    > slope vectors.

Well, not quite.  AFAIR, the reasons I did not add the option for
spline()  were mostly

- using  splinefun() is uniformly more flexible than using spline()
  {you can always get an (x,y) coordinate list from
   splinefun()'s result later}

- splinefun() is using's R feature of "(non-trivial) closure", i.e, 
  it returns a *function* containing its own state

- convenience (less work, notably less maintenance burden)

Still, in spite of the above:  If somebody provides minimal patches
(keeping *elegant* code) to allow spline() to also allow method="monoH.FC",
I'd consider applying that.
For now, I'd rather amend the documentation (as Samuel proposes)

    > Note that my package kubik, provides a range of functions for working
    > with cubic Hermite splines.

That's interesting.  For years, I had wanted to add a bit more
functionality to R's builtin (but not widely known !!) package 'splines',
and just today a colleague asked me about spline interpolation
with general 2nd derivative boundary conditions

   s''(x_1) = s2_1,  s''(x_n) = s2_2

generalizing the usual ( "natural" ) boundary conditions

   s''(x_1) = 0,     s''(x_n) = 0

and I'd "hope" it should really only need a few lines of R code
to generalize from natural interpolating splines to such very
slightly more general ones.
(I don't see very quickly how to do this with 'kubik' either,
but I've only looked for 5 minutes).

---

Note that our CRAN package 'cobs'  is really for
(robust, namely quantile) regression splines where the user can also
ask for monotonicity, convexity, concavity of s() and for bound
constraints in different regions
(and the implementation is fast for larger 'n', thanks to using
 sparse matrices)... which seems partly a generalization of  'kubik'
as it's not only (just) for interpolation and still allows many
shape and bound constraints.
 
> citation("cobs")

To cite the cobs package in publications use:

  Pin T. Ng and Martin Maechler (2020). COBS -- Constrained B-splines (Sparse matrix
  based). R package version 1.3-4. URL https://CRAN.R-project.org/package=cobs

Ng P, Maechler M (2007). “A Fast and Efficient Implementation of Qualitatively
Constrained Quantile Smoothing Splines.” _Statistical Modelling_, *7*(4),
 315-328. <URL:http://smj.sagepub.com/content/7/4/315.abstract>.



More information about the R-help mailing list