| bsplines | R Documentation |
An implementation of Carl de Boor's recursive algorithm for building B-splines.
bsplines(x, iknots = NULL, df = NULL, bknots = range(x), order = 4L)
x |
a numeric vector |
iknots |
internal knots |
df |
degrees of freedom: sum of the order and internal knots. Ignored
if |
bknots |
boundary knot locations, defaults to |
order |
order of the piecewise polynomials, defaults to 4L. |
There are several differences between this function and
bs.
The most important difference is how the two methods treat the right-hand end
of the support. bs uses a pivot method to allow for
extrapolation and thus returns a basis matrix where non-zero values exist on
the max(Boundary.knots) (bs version of
bsplines's bknots). bsplines use a strict definition of
the splines where the support is open on the right hand side, that is,
bsplines return right-continuous functions.
Additionally, the attributes of the object returned by bsplines are
different from the attributes of the object returned by
bs. See the vignette(topic = "cpr", package =
"cpr") for a detailed comparison between the bsplines and
bs calls and notes about B-splines in general.
C. de Boor, "A practical guide to splines. Revised Edition," Springer, 2001.
H. Prautzsch, W. Boehm, M. Paluszny, "Bezier and B-spline Techniques," Springer, 2002.
plot.cpr_bs for plotting the basis,
bsplineD for building the basis matrices for the first and
second derivative of a B-spline.
See update_bsplines for info on a tool for updating a
cpr_bs object. This is a similar method to the
update function from the stats package.
vignette(topic = "cpr", package = "cpr") for details on B-splines and
the control polygon reduction method.
# build a vector of values to transform
xvec <- seq(-3, 4.9999, length = 100)
# cubic b-spline
bmat <- bsplines(xvec, iknots = c(-2, 0, 1.2, 1.2, 3.0), bknots = c(-3, 5))
bmat
# plot the splines
plot(bmat) # each spline will be colored by default
plot(bmat, color = FALSE) # black and white plot
plot(bmat, color = FALSE) + ggplot2::aes(linetype = spline) # add a linetype
# Axes
# The x-axis, by default, show the knot locations. Other options are numeric
# values, and/or to use a second x-axis
plot(bmat, show_xi = TRUE, show_x = FALSE) # default, knot, symbols, on lower
# axis
plot(bmat, show_xi = FALSE, show_x = TRUE) # Numeric value for the knot
# locations
plot(bmat, show_xi = TRUE, show_x = TRUE) # symbols on bottom, numbers on top
# quadratic splines
bmat <- bsplines(xvec, iknots = c(-2, 0, 1.2, 1.2, 3.0), order = 3L)
bmat
plot(bmat) + ggplot2::ggtitle("Quadratic B-splines")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.