Spline plot type

Description

Type function for plotting a cubic (or Hermite) spline interpolation. Arguments are passed to spline; see this latter function for default argument values.

Usage

type_spline(
  n = NULL,
  method = "fmm",
  xmin = NULL,
  xmax = NULL,
  xout = NULL,
  ties = mean
)

Arguments

n if xout is left unspecified, interpolation takes place at n equally spaced points spanning the interval [xmin, xmax].
method specifies the type of spline to be used. Possible values are “fmm”, “natural”, “periodic”, “monoH.FC” and “hyman”. Can be abbreviated.
xmin, xmax left-hand and right-hand endpoint of the interpolation interval (when xout is unspecified).
xout an optional set of values specifying where interpolation is to take place.
ties handling of tied x values. The string “ordered” or a function (or the name of a function) taking a single vector argument and returning a single number or a length-2 list of both, see approx and its ‘Details’ section, and the example below.

Details

The inputs can contain missing values which are deleted, so at least one complete (x, y) pair is required. If method = “fmm”, the spline used is that of Forsythe, Malcolm and Moler (an exact cubic is fitted through the four points at each end of the data, and this is used to determine the end conditions). Natural splines are used when method = “natural”, and periodic splines when method = “periodic”.

The method “monoH.FC” computes a monotone Hermite spline according to the method of Fritsch and Carlson. It does so by determining slopes such that the Hermite spline, determined by \((x_i,y_i,m_i)\), is monotone (increasing or decreasing) iff the data are.

Method “hyman” computes a monotone cubic spline using Hyman filtering of an method = “fmm” fit for strictly monotonic inputs.

These interpolation splines can also be used for extrapolation, that is prediction at points outside the range of x. Extrapolation makes little sense for method = “fmm”; for natural splines it is linear using the slope of the interpolating curve at the nearest data point.

Examples

library("tinyplot")

# "spline" type convenience string
tinyplot(dist ~ speed, data = cars, type = "spline")

# Use `type_spline()` to pass extra arguments for customization
tinyplot(dist ~ speed, data = cars, type = type_spline(method = "natural", n = 25),
    add = TRUE, lty = 2)