Spline Search and Tuning

Practical tuning guidance for crs, including search size, smoothness, knot selection, and memory-aware spline search.
Keywords

crs, spline search, knots, degree, segments, cv.df.min, smoothness

This page describes the principal crs controls for search cost, smoothness, degree, and knot placement. Narrow the search only when the resulting spline class remains appropriate for the statistical problem.

Why can the search take time?

crs is often searching over:

  • spline degree,
  • knot or segment structure,
  • basis type,
  • categorical handling.

Runtime therefore depends on the size of the requested search space as well as the sample and basis dimensions.

If the search still feels long

Current crs releases use compact single-line status I/O during NOMAD search, so the usual next step is not to change optimizer display settings. If progress is slow, first assume the requested search space is large and reduce the problem before concluding anything more dramatic.

The controls below are the practical levers to reach for first.

CRS NOMAD budget controls

Current crs releases choose route-specific defaults for NOMAD black-box evaluation budgets after the search route is known. Continuous-only searches and kernel/categorical searches therefore no longer have to share one blunt default.

If you need to override the defaults, use the public budget controls directly:

## Override CRS NOMAD budgets only when the default search is not appropriate
model <- crs(y ~ x1 + x2,
  max.bb.eval = 10000,
  max.eval = 1000)

max.bb.eval controls the black-box evaluation budget, while max.eval controls repeated NOMAD point-lookup budgets. Summaries now report elapsed time and cache diagnostics more clearly, so inspect the fitted object before loosening a search globally.

Reduce the search space deliberately

If you need a smaller problem first, the usual levers are:

  • lower degree.max,
  • lower segments.max,
  • use complexity = "degree" or another narrower search,
  • use basis = "additive" when additivity is a defensible restriction.

The additive basis can reduce the combinatorics materially, but it changes the model class and should be used only when additivity is defensible.

What if the fitted spline is not smooth enough?

Cross-validation may select a rougher spline than anticipated because that candidate minimizes the chosen criterion over the stated search space.

Impose a minimum degree when the scientific problem requires a smoother spline:

## Impose a minimum spline degree when you want a smoother fitted object
model <- crs(y ~ x1 + x2, degree.min = 3)

This makes the smoothness restriction explicit in the fitted model.

Can crs recover linear regression?

The model family includes a linear-regression-style special case.

## Recover the linear-regression-style special case inside crs
model_crs <- crs(y ~ x1 + x2 + z1 + z2,
  cv = "none",
  kernel = FALSE,
  degree = rep(1, 2),
  segments = rep(1, 2))

This is the simple linear-regression-style special case already highlighted on Splines.

Quantile regression splines

Set tau to estimate the conditional quantile \(q_\tau(x)\) rather than the conditional mean \(E(Y\mid X=x)\).

## Use tau to target a conditional quantile rather than a conditional mean
model_q <- crs(y ~ x1 + x2, tau = 0.5)

That gives the conditional median when tau = 0.5, or any other conditional quantile for tau in (0, 1).

Retrieving knots

Once a model is fit, the practical route to the knot locations depends on whether uniform or quantile knots were used. The key quantity to inspect is the selected number of segments for each predictor.

For a single predictor x1, use this knot-retrieval pattern:

## Recover uniform knot locations from the selected segment count
seq(min(x1), max(x1), length.out = model$segments[1] + 1)

for uniform spacing, or

## Recover quantile knot locations from the selected segment count
quantile(x1, probs = seq(0, 1, length.out = model$segments[1] + 1))

for quantile spacing.

Compare against a parametric baseline when useful

To compare a parametric model and a spline model on a common predictive criterion, compare their cross-validation scores rather than only their fitted curves or summary tables.

Where to go next

Back to top