| varyknotsIC | R Documentation |
Evaluates an information criterion (BIC, AIC, or AICc) for a regression of
y on a spline basis of x where the number and locations of
interior knots are encoded in the chromosome. Designed for use as a GA
objective/fitness function. The spline basis is constructed via [splineX()].
varyknotsIC(
knot_bin,
plen = 0,
y,
x,
x_unique,
x_base = NULL,
degree = 3L,
type = c("ppolys", "ns", "bs"),
intercept = TRUE,
ic_method = "BIC"
)
knot_bin |
Integer vector (chromosome). Gene 1 stores m, the number of
interior knots. Genes 2:(1+m) are indices into |
plen |
Unused placeholder kept for API compatibility; ignored. |
y |
Numeric response vector of length |
x |
Numeric predictor (same length as |
x_unique |
Optional numeric vector of unique candidate knot locations.
If missing or |
x_base |
Optional matrix (or vector) of additional covariates to include linearly alongside the spline basis; coerced to a matrix if supplied. |
degree |
Integer polynomial degree for |
type |
One of |
intercept |
Logical; forwarded to [splineX()]. For |
ic_method |
Which information criterion to return: |
If m = 0, the model is a pure-linear baseline using only an intercept
and x_base: X <- cbind(1, x_base) (no spline terms).
For m > 0, the spline block is built with [splineX()] using the selected
interior knots, with X <- cbind(splineX(..., intercept=intercept), x_base).
The criteria are computed as:
\mathrm{BIC} = n \log(\mathrm{SSRes}/n) + p \log n,
\mathrm{AIC} = n \log(\mathrm{SSRes}/n) + 2p,
\mathrm{AICc} = n \log(\mathrm{SSRes}/n) + 2p +
\frac{2p(p+1)}{n-p-1},
where \mathrm{SSRes} is the residual sum of squares and p is the
number of columns in the design matrix X.
A single numeric value: the requested information criterion (lower is
better). Returns Inf for invalid chromosomes/inputs.
This function allows m=0 (no spline terms) so that the GA can
compare against a pure-linear baseline (intercept + x_base).
Spacing constraints (e.g., minimum distance between indices) should be
enforced by the GA operators or an external penalty.
[fixknotsIC()], [splineX()], bs, ns
## Example with 'mcycle' data (MASS)
# y <- mcycle$accel; x <- mcycle$times
# x_unique <- sort(unique(x))
# chrom <- c(5, 24, 30, 46, 49, 69, length(x_unique) + 1)
# varyknotsIC(chrom, y=y, x=x, x_unique=x_unique,
# type="ppolys", degree=3, ic_method="BIC")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.