Description Usage Arguments Details Author(s) References See Also Examples
An implementation of Carl de Boor's recursive algorithm for building B-splines.
1 |
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. |
The difference between this function and splines::bs
come in the
attributes associated with the output and default options. The
cpr::bsplines
call is intended to simplify the work needed with
respect to the control polygon reduction. Further, the implementation of
cpr::bsplines
is in C++ and tends to be faster than
splines::bs
.
See the vignette("cpr-pkg", package = "cpr")
for a detailed
comparison between the bsplines
and bs
calls.
Peter DeWitt dewittpe@gmail.com
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # build a vector of values to transform
xvec <- seq(-3, 5, length = 100)
# cubic b-spline
bmat <- bsplines(xvec, iknots = c(-2, 0, 0.2))
bmat
# plot the splines
plot(bmat)
# If you want a second x-axis to show the x-values try the following:
second_x_axis <- round(stats::quantile(xvec, probs = seq(0, 1, by = .2)), 2)
plot(bmat) +
ggplot2::annotate(geom = "text", x = second_x_axis, y = -0.02, label = second_x_axis) +
ggplot2::annotate(geom = "linerange", x = second_x_axis, ymin = -0.05, ymax = -0.04) +
ggplot2::coord_cartesian(ylim = c(0, 1))
# quadratic splines
bmat <- bsplines(xvec, iknots = c(-2, 0, 0.2), order = 3L)
bmat
plot(bmat) + ggplot2::ggtitle("Quadratic B-splines")
|
Matrix dims: [100 x 7]
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1.0000000 0.0000000 0.000000000 0.000000e+00 0 0 0
[2,] 0.7766379 0.2170667 0.006240459 5.496587e-05 0 0 0
[3,] 0.5892895 0.3864669 0.023803888 4.397270e-04 0 0 0
[4,] 0.4347887 0.5127739 0.050953366 1.484079e-03 0 0 0
[5,] 0.3099694 0.6005608 0.085951971 3.517816e-03 0 0 0
[6,] 0.2116657 0.6544008 0.127062781 6.870734e-03 0 0 0
Matrix dims: [100 x 6]
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1.0000000 0.0000000 0.000000000 0 0 0
[2,] 0.8449138 0.1529096 0.002176649 0 0 0
[3,] 0.7028875 0.2884059 0.008706595 0 0 0
[4,] 0.5739210 0.4064891 0.019589838 0 0 0
[5,] 0.4580145 0.5071591 0.034826378 0 0 0
[6,] 0.3551678 0.5904159 0.054416216 0 0 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.