This function calculates the B-Spline basis penalty. It follows the procedure outlined in the paper by Zheyuan Li, Jiguo Cao, 2022 "General P-Splines for Non-Uniform B-Splines" doi:10.48550/arXiv.2201.06808 . For equidistant knots it coincides with the usual penalty based on the identitiy. For non-equidistant knots it is a weighted penalty with respect to the knot distances.
penalty(knots, order, max_diff = 999L)
Vector of knots.
Order of the Basis (degree + 1).
Maximum difference order to calculate.
Returns a list of (order - 1) penalty matrices.
if (FALSE) {
# Equidisan knots with order 2
knots <- 1:10
P <- penalty(knots, order = 2)
print(P[[1]]) # First differences
# Non-equidistant knots
knots <- c(0, 0, 0, 0, 1, 3, 4, 4, 4, 4)
P <- penalty(knots, order = 4)
print(P[[1]]) # First differences
print(P[[2]]) # Second differences
print(P[[3]]) # Third differences
}