Package 'ibs'

Title: Integral of B-Spline Functions
Description: Calculate B-spline basis functions with a given set of knots and order, or a B-spline function with a given set of knots and order and set of de Boor points (coefficients), or the integral of a B-spline function.
Authors: Feng Chen
Maintainer: Feng Chen <[email protected]>
License: GPL (>= 2)
Version: 1.4
Built: 2025-01-10 05:19:02 UTC
Source: https://github.com/cran/ibs

Help Index


A short title line describing what the package does

Description

Evaluate the integral of a B-spline function, or the B-spline function itself, or the B-spline basis functions.

Details

The function bsbases calculates the values of the B-spline basis functions defined by knots knots and order ord at sites x. The function bspline evaluates the B-spline function defined by knots knots, order ord, and coefficients coef at sites x. The function ibs calculates the integrals of the B-spline function defined by knots knots, order ord, and coefficients coef from the smallest knot to each of the values in x.

Author(s)

Creator: Feng Chen

Maintainer: Feng Chen <[email protected]>

References

de Boor, C. (2001) A Practical Guide to Splines. Revised Edition. Springer: New York.

See Also

splineDesign


B-spline bases

Description

Evaluate the B-spline basis function at the x value(s).

Usage

bsbases(x, knots, ord)

Arguments

x

Numerical value or vector. The value(s) at which to evaluate the B spline bases.

knots

Numerical vector. The knot positions/sites of the B-spline bases.

ord

An integer >=1. The order of the B-spline bases. Equals degree plus 1.

Value

A numerical matrix of length(x) rows and length(knots)-ord columns.

Note

In contrast to the implementation based on the splineDesign function from the splines package, this version of the B-spline basis functions are left-continuous at the rightmost knot.

Author(s)

Feng Chen <[email protected]>

References

de Boor, C. (2001) A Practical Guide to Splines. Revised Edition. Springer: New York.

See Also

splineDesign

Examples

kns <- c(rep(0,4),1:4*0.2,rep(1,4))
round(bsbases(0:5/5,kns,2),10)
round(splines::splineDesign(kns,0:5/5,2),10)

B-spline function

Description

Evaluate the value of the B-spline function with knots knots, order ord, and coefficients coef at value(s) x.

Usage

bspline(x, knots, ord, coef = rep(1, length(knots) - ord))

Arguments

x

Numerical value or vector. The value(s) at which to evaluate the B-spline.

knots

Numerical vector. The knot positions/sites of the B-spline function.

ord

An integer >=1. The order of the B-spline function. Equals degree plus 1.

coef

A numerical vector. The coefficients (de Boor points) defining the B-spline function.

Value

A scalar or a vector of length equal to that of x.

Note

In contrast to the implementation based on the splineDesign function from the splines package, this version of the B-spline function is left-continuous at the rightmost knot site.

Author(s)

Feng Chen <[email protected]>

References

de Boor, C. (2001) A Practical Guide to Splines. Revised Edition. Springer: New York.

See Also

splineDesign

Examples

kns <- c(rep(0,4),1:4*0.2,rep(1,4))
bspline(0:10/10,kns,3,rep(1,length(kns)-3))
splines::splineDesign(kns,0:10/10,3)%*%rep(1,length(kns)-3)

Integratal of a B-spline function

Description

Calculate the integral of a B-spline function.

Usage

ibs(x, knots, ord=4, coef = rep(1, length(knots) - ord))

Arguments

x

Numerical value or vector. The value(s) at which to evaluate the integral of the B-spline; must be in the interval bewteen the smallest knot to the (nknots-ord)th largest knot.

knots

Numerical vector. The knot positions/sites of the B-spline function to be integrated.

ord

An integer >=1. The order of the B-spline integrand function to be integrated. Equals degree plus 1.

coef

A numerical vector. The coefficients (de Boor points) defining the B-spline integrand function.

Details

The function returns the integral(s) of the B-spline function specified by knots knots, order ord, and coefficients coef, from the minimum knot position to each x value. The evaluation is based on a closed form expression of the integral in terms of higher order B-splines, given on page 128 of de Boor (2001).

Value

A numerical equal to the integral(s).

Author(s)

Feng Chen <[email protected]>

References

de Boor, C (2001) A Practical Guide to Splines. Revised Edition. Springer: New York.

See Also

bspline

Examples

kns <- c(rep(0,4),1:4*0.2,rep(1,4))
co <- rnorm(length(kns)-3)
integrate(bspline,knots=kns,ord=3,coef=co,0,0.95)
integrate(function(x)bsbases(x,kns,3) %*% co,0,0.95)
ibs(0.95,kns,3,co)