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
- 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:
- 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
and
are the smallest and largest value in the x vector, then interior knots are placed evenly at
In addition, the BSPLINE function places d exterior knots that are less than
and max(d,1) exterior knots that are greater than
. The exterior knots are evenly spaced and start at
and
, respectively. In this case the BSPLINE function returns a matrix with m rows and
columns.
The BSPLINE function computes B-splines of degree d. Suppose that denotes the jth B-spline of degree d in the knot sequence
. De Boor (1978) defines the splines based on the following relationships:
Note that De Boor (1978) expresses B-splines in terms of order rather than degree; in his notation . B-splines have many interesting properties, including the following:
See De Boor (1978) for more details. The BSPLINE function defines B-splines of degree 0 as nonzero when .
A typical knot vector for calculating B-splines consists of d exterior knots smaller than the smallest data value, and 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 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.02083 | 0.47917 | 0.47917 | 0.02083 | 0 | 0 | 0 |
| 0 | 0.16667 | 0.66667 | 0.16667 | 0 | 0 | 0 |
| 0 | 0 | 0.02083 | 0.47917 | 0.47917 | 0.02083 | 0 |
| 0 | 0 | 0 | 0.1215 | 0.65717 | 0.22117 | 0.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.5 | 0.5 | 2E-24 | 0 | 0 | 0 | 0 |
| 74E-5 | 0.537 | 0.462 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0.012 | 0.63 | 0.358 | 0 |
| 0 | 0 | 0 | 0 | 2E-24 | 0.5 | 0.5 |