| fixknotsIC | R Documentation |
Computes an information criterion (BIC, AIC, or AICc) for a regression of
y on a spline basis of x when the number of interior knots is
fixed. This is designed to be used as a fitness/objective function inside a
GA search where the chromosome encodes the indices of the interior knots.
fixknotsIC(
knot_bin,
plen = 0,
y,
x,
x_unique,
x_base = NULL,
fixedknots,
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 with other objective functions. Ignored. |
y |
Numeric response vector of length |
x |
Numeric predictor (same length as |
x_unique |
Optional numeric vector of unique candidate knot locations.
If |
x_base |
Optional matrix (or vector) of additional covariates to include linearly alongside the spline basis. If supplied, it is coerced to a matrix and column-bound to the design. |
fixedknots |
Integer |
degree |
Integer polynomial degree for |
type |
One of |
intercept |
Logical; forwarded to [splineX()]. For |
ic_method |
Character; which information criterion to return:
|
We decode the interior indices up to the sentinel length(x_unique)+1,
validate them (finite, interior, non-duplicated), sort the resulting knot
locations internally, and build the design as
X <- cbind(splineX(..., intercept=intercept), x_base).
Invalid chromosomes/inputs return Inf.
A single numeric value: the requested information criterion. Lower is
better. Returns Inf for invalid chromosomes/inputs.
[varyknotsIC()], [splineX()], bs, ns
library(MASS)
y <- mcycle$accel
x <- mcycle$times
x_unique <- sort(unique(x))
# chromosome encoding 5 interior knot indices with sentinel:
chrom <- c(5, 24, 30, 46, 49, 69, length(x_unique) + 1)
fixknotsIC(chrom,
y = y, x = x, x_unique = x_unique,
fixedknots = 5, ic_method = "BIC"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.