When working with data on a rectangular grid, the problem can be expressed in terms of matrices. Let
M be an
m ×
n matrix of data. The B-spline number and order (polynomial degree + 1) can be chosen independently along the two dimensions of the
m ×
n grid. Each B-spline is evaluated at each point of the grid, so that the values for the B-splines in each direction form matrices, with one column for each spline. Following the notation of Eilers et al.,
16 let
B̆ denote the
m ×
K matrix of B-splines down the rows and
B the
n ×
L matrix across the columns of
M, where
K and
L are the corresponding numbers of B-splines. The aim is then to fit
M with a surface written as
where
β is a
K ×
L matrix of basis function coefficients and
B′ denotes the transpose of
B. It should be noted that
β is typically much smaller than
M. Using equation 2, Eilers et al.
16 recently showed that, if a roughness penalty (from which the name P-spline originates) is used to control smoothing, the best fit is achieved when the matrix of coefficients
β satisfies the penalized regression equation
The vec(·) function in equation 3 “flattens” a matrix into a column vector by stacking its columns, ⊙ is the element by element product of two matrices and
W is an
m ×
n matrix of weights. The
KL ×
KL matrix
F is a function of the spline matrices
B̆ and
B and the weights
W. The
KL ×
KL penalty matrix
P is described in the following text. This equation can be solved for vec(
β), a
KL × 1 column vector, which is then rearranged to yield the
K ×
L coefficient matrix
β.