nl_compare: Built-in model comparison workflow

View source: R/nl_compare.R

nl_compareR Documentation

Built-in model comparison workflow

Description

Compares a nonlinear spline model against simpler alternatives—a linear model and optional polynomial terms—to help researchers justify the spline approach over simpler specifications.

For each model, the function reports:

  • AIC and BIC

  • Log-likelihood (and likelihood-ratio test versus the linear model where available)

  • Number of parameters (df)

  • Residual variance / deviance

Usage

nl_compare(
  object,
  polynomial_degrees = c(2L, 3L),
  digits = 3L,
  return_models = FALSE
)

Arguments

object

An nl_fit object (the spline model to compare against).

polynomial_degrees

Integer vector of polynomial degrees to include as additional comparators. Default c(2L, 3L). Set to integer(0) to skip.

digits

Integer; decimal places for the output table. Default 3.

return_models

Logical; if TRUE, also returns the fitted comparison model objects. Default FALSE.

Value

A list (invisibly) of class "nl_compare" with:

table

A data frame with the comparison statistics.

models

Named list of fitted models (when return_models = TRUE).

best

Name of the model with the lowest AIC.

The table is pretty-printed automatically.

See Also

nl_fit, nl_knots

Examples

## Not run: 
fit <- nl_fit(data = mydata, y = "score", x = "age", df = 4)
nl_compare(fit)
nl_compare(fit, polynomial_degrees = c(2, 3, 4))

## End(Not run)


MultiSpline documentation built on April 16, 2026, 9:06 a.m.