Skip to contents

Fit 2D parametric polynomial curve with LOOCV-2D or AIC degree selection

Usage

fit_trajectory_poly(
  points,
  t = numeric(),
  max_degree = 3L,
  fixed_degree = 0L,
  criterion = "loocv",
  basis = "orthogonal"
)

Arguments

points

Numeric matrix (n x 2) of trajectory coordinates

t

Numeric vector of time values (length n)

max_degree

Maximum polynomial degree (default 3)

fixed_degree

Exact degree to use when >= 1

criterion

Criterion for degree selection: "loocv" or "aic"

basis

Polynomial basis used for fitting: "orthogonal" or "raw"

Examples

t <- seq(0, 1, length.out = 6)
pts <- cbind(1 + 2 * t, 4 - 3 * t)  # a straight line
fit <- fit_trajectory_poly(pts, t = t, fixed_degree = 1L, basis = "raw")
fit$degree
#> [1] 1
fit$coeffs_x  # intercept 1, slope 2
#>      [,1]
#> [1,]    1
#> [2,]    2
fit$coeffs_y  # intercept 4, slope -3
#>      [,1]
#> [1,]    4
#> [2,]   -3