library("gamlss2")
data("SpirometryUS")
## subset for female
d <- subset(SpirometryUS, gender == "male")
## Automatically select zero through four free interior knots
m1 <- gamlss2(fev1 ~ fk(age, nk = 1) | ., data = d, family = NO)
## estimated effects
plot(m1)
## predict quantiles
qu <- c(0.025, seq(0.1, 0.9, by = 0.1), 0.975)
fit <- quantile(m1, probs = qu)
## plot
plot(fev1 ~ age, data = d)
i <- order(d$age)
matlines(d$age[i], fit[i, ],
lty = 1, lwd = 2, col = c(2, rep(4, ncol(fit) - 1)))Free-Knot Regression Splines for GAMLSS
Description
Constructs a univariate regression spline whose interior knot locations, and optionally the number of interior knots, are selected from the current weighted working response.
Usage
fk(x, k = 10L, nk = NULL, degree = 1L,
criterion = "bic", knots = NULL, K = NULL,
reselect = FALSE, optim.control = list(), ...)
Arguments
x
|
A numeric covariate. |
k
|
Integer, the largest number of free interior knots considered when |
nk
|
Integer, optional fixing the number of free interior knots. The locations are still estimated. |
degree
|
Integer, the polynomial degree of the B-spline basis. The default |
criterion
|
Character selection criterion. Available choices are |
knots
|
Optional numeric vector of fixed interior knot locations. The values must be distinct and strictly inside the range of |
K
|
Optional nonnegative penalty multiplier used by |
reselect
|
Logical. If |
optim.control
|
Named list passed as the |
…
|
Additional entries merged into |
Details
For each candidate number of interior knots, fk() uses a B-spline basis with fixed, repeated boundary knots. Interior knots are represented by positive ordered gaps. This removes permutation ambiguity and prevents knot crossings during optimization.
Conditional on the knot locations, spline coefficients are profiled out by weighted least squares. Knot optimization therefore only operates on the interior locations. The fitted model term is centered.
When nk = NULL, models with zero through k interior knots are compared using criterion. Effective degrees of freedom include both the centered spline coefficients and the estimated interior knot locations. Fixed locations supplied through knots do not add knot-location degrees of freedom.
Value
The constructor returns an object of classes “special” and “fk”.
See Also
gamlss2, special_terms