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" tools:::Rd_expr_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. In addition to the above, we added the possibility to calculate periodic penalties which are based on the periodic differencing matrices.
periodic: Whether the penalties should be periodic or not.
max_diff: Maximum difference order to calculate.
Returns
Returns a list of (order - 1) penalty matrices.
Examples
## Not run:# Equidistant knots with order 2knots <-1:10P <- penalty(knots, order =2)print(P[[1]])# First differences# Non equidistant knotsknots <- c(0,0,0,0,1,3,4,4,4,4)P <- penalty(knots, order =4)print(P[[1]])# First differencesprint(P[[2]])# Second differencesprint(P[[3]])# Third differences# Periodic penalty for equidistant knotsoder <-4deg <- order -1knots <-1:15penalty(knots, order = order, periodic =TRUE)[[1]]penalty(knots, order = order, periodic =TRUE)[[2]]penalty(knots, order = order, periodic =TRUE)[[3]]## End(Not run)