Language Reference

BSPLINE Function

BSPLINE (x, d, k <, i> ) ;

This function is supported by the IML procedure and the iml action.

The BSPLINE function computes a B-spline basis. The arguments to the BSPLINE function are as follows:

x

is an m times 1 or 1 times m numeric vector.

d

is a nonnegative numeric scalar value that specifies the degree of the B-spline. The order of a B-spline is one greater than the degree.

k

is a numeric vector of size n that contains the B-spline knots. If k is a scalar that contains a missing value, the knot positions are determined by the i argument. Otherwise, the elements of the knot vector must satisfy the following requirements:

  • The elements of the knot vector must be nondecreasing: k Subscript j minus 1 Baseline less than or equals k Subscript j for j equals 2 comma ellipsis comma n.

  • At least d knots must be less than or equal to the smallest data value.

  • At least max(d,1) knots must be greater less than or equal to the largest data value.

i

is an optional argument that specifies the number of interior knots. This argument is used only when k is a scalar that contains a missing value. In this case the BSPLINE function constructs a vector of knots as follows: If x Subscript left parenthesis 1 right parenthesis and x Subscript left parenthesis m right parenthesis are the smallest and largest value in the x vector, then interior knots are placed evenly at

x Subscript left parenthesis 1 right parenthesis Baseline plus left parenthesis x Subscript left parenthesis m right parenthesis Baseline minus x Subscript left parenthesis 1 right parenthesis Baseline right parenthesis j divided by left parenthesis i plus 1 right parenthesis comma j equals 1 comma ellipsis comma i

In addition, the BSPLINE function places d exterior knots that are less than x Subscript left parenthesis 1 right parenthesis and max(d,1) exterior knots that are greater than x Subscript left parenthesis m right parenthesis. The exterior knots are evenly spaced and start at x Subscript left parenthesis 1 right parenthesis Baseline minus 10 Superscript negative 12 and x Subscript left parenthesis m right parenthesis Baseline plus 10 Superscript negative 12, respectively. In this case the BSPLINE function returns a matrix with m rows and i plus d plus 1 columns.

The BSPLINE function computes B-splines of degree d. Suppose that upper B Subscript j Superscript d Baseline left parenthesis x right parenthesis denotes the jth B-spline of degree d in the knot sequence k 1 comma ellipsis comma k Subscript n Baseline. De Boor (1978) defines the splines based on the following relationships:

upper B Subscript j Superscript 0 Baseline left parenthesis x right parenthesis equals StartLayout Enlarged left brace 1st Row 1st Column 1 2nd Column k Subscript j Baseline less than or equals x less than k Subscript j plus 1 Baseline 2nd Row 1st Column 0 2nd Column otherwise EndLayout

and for d greater than 0

StartLayout 1st Row 1st Column upper B Subscript j Superscript d Baseline left parenthesis x right parenthesis 2nd Column equals 3rd Column w Subscript j Superscript d Baseline left parenthesis x right parenthesis upper B Subscript j Superscript d minus 1 Baseline left parenthesis x right parenthesis plus left parenthesis 1 minus w Subscript j plus 1 Superscript d Baseline left parenthesis x right parenthesis right parenthesis upper B Subscript j plus 1 Superscript d minus 1 Baseline left parenthesis x right parenthesis 2nd Row 1st Column w Subscript j Superscript d Baseline left parenthesis x right parenthesis 2nd Column equals 3rd Column StartFraction x minus k Subscript j Baseline Over k Subscript j plus d Baseline minus k Subscript j Baseline EndFraction EndLayout

Note that De Boor (1978) expresses B-splines in terms of order rather than degree; in his notation upper B Subscript j comma d Baseline equals upper B Subscript j Superscript d minus 1. B-splines have many interesting properties, including the following:

  • sigma summation Underscript j Endscripts upper B Subscript j Superscript d Baseline equals 1

  • The sequence upper B Subscript j Superscript d is positive on d plus 1 knots and zero elsewhere.

  • The B-spline upper B Subscript j Superscript d is a piecewise polynomial of at most d plus 1 pieces.

  • If k Subscript j Baseline equals k Subscript j plus d, then upper B Subscript j Superscript d minus 1 Baseline equals 0.

See De Boor (1978) for more details. The BSPLINE function defines B-splines of degree 0 as nonzero when k Subscript j Baseline less than x less than or equals k Subscript j plus 1.

A typical knot vector for calculating B-splines consists of d exterior knots smaller than the smallest data value, and max left brace d comma 1 right brace exterior knots larger than the largest data value. The remaining knots are the interior knots.

For example, the following statements creates a B-spline basis with three interior knots. The BSPLINE function returns a matrix with 3 plus d plus 1 equals 7 columns, shown in Figure 63.

x     = {2.5 3 4.5 5.1};     /* data range is [2.5, 5.1] */
knots = {0 1 2 3 4 5 6 7 8}; /* three interior knots at x=3, 4, 5 */
bsp = bspline(x, 3, knots);
print bsp[format=best7.];

Figure 62: B-Spline Basis

bsp
0.020830.479170.479170.02083000
00.166670.666670.16667000
000.020830.479170.479170.020830
0000.12150.657170.221170.00017


If you pass an x vector of data values, you can also rely on the BSPLINE function to compute a knot vector for you. For example, the following statements compute B-splines of degree 2 based on four equally spaced interior knots:

bsp2 = bspline(x, 2, ., 4);
print bsp2[format=best5.];

The resulting matrix is shown in Figure 63.

Figure 63: B-Spline Basis with Four Interior Knots

bsp2
0.50.52E-240000
74E-50.5370.4620000
0000.0120.630.3580
00002E-240.50.5


Last updated: April 11, 2025