Smoothing Splines with Optimized Unequal Knot Spacing

I have some (x,y) data with equally-spaced x’s. I would like to smooth the data using (up to) 4 cubic splines and obtain the equations for each spline. I would like the knots connecting the splines to move to an optimal position which minimizes the total R^2 distance from the splines to the raw data.

I don’t know what the above mathematical approach would be called to research it further. I read about smoothing splines, but the \lambda parameter seems at odds with my desire to fix the number of knots to unequal distances. I also see that basis splines are commonly implemented in Julia packages, but I am having trouble understanding them and if they would suit my needs. Why, for instance, would I use a cubic basis spline instead of a natural cubic spline? Spline interpolation which creates a spline between every consecutive data point would not suit my needs.

Moreover, I don’t know what the best Julia package for this would be. I found several packages that seem to be related to curve fitting, but I could use some advice on which to try implementing.

I am fine with initially taking a brute-force approach for determining the knot locations if optimization adds too much complexity. I could compute every possible combination of knot locations in a loop and then take the minimum R^2. The length of my data is of order 100.


They are equivalent, but using basis functions allows higher order splines and more flexible use cases (eg you want to match derivatives at some point, etc), and admits a more general linear algebra formulation.

I would recommend investing into understanding B-splines, but generally moving the knots in an undisciplined way can result in all sorts of wacky overfitting. The literature has various algorithms for doing this in an organized wy, the keywords you may want to use are “free-knot splines”.