ibs: Integration for B-splines

Description Usage Arguments Details Value References Examples

View source: R/ibs.R

Description

Calculate the integral of a B-spline function.

Usage

1
ibs(x, knots = NULL, 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 bewteen min(knots) and max(knots).

knots

A numeric vector of knot positions.

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).

References

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(splines)
f <- function(x) x + 2 * x^2 - 3 * x^3 
n <- 200
set.seed(123)
x <- runif(n)
y <- f(x) + rnorm(n, sd = 0.1)
kns <- c(rep(0, 4), 1:4 * 0.2, rep(1, 4))
bs.c <- splineDesign(kns, x, 4)
coeff <- as.matrix(lm(y ~ bs.c-1)$coefficients)
f.b <- function(x, coeff) splineDesign(kns, x, 4) %*% coeff
integrate(f.b, 0, 1, coeff)
ibs(1,kns,4,coeff)
integrate(f, 0, 1)
plot(x,y)
curve(f(x), add = TRUE)
points(x,fitted(lm(y~bs.c-1)),col="blue",lty=1)

Example output

0.4174408 with absolute error < 6.4e-05
[1] 0.4174406
0.4166667 with absolute error < 4.6e-15

IntegrateBs documentation built on May 2, 2019, 6:08 a.m.

Related to ibs in IntegrateBs...