This function fits free-knot splines to data using every value for the number of knots between minknot
and maxknot
. The number of knots is then chosen to optimize a fit criterion. The free-knot spline with the optimum number of knots is returned.
fit.search.numknots(x, y, degree, minknot = 1, maxknot = 5,
alg = "LS", search = "genetic",
knotnumcrit = "adjGCV", k = 2, d = 3, seed = 5,
stream = 0)
A vector containing the values of the independent variable.
A vector containing the values of the dependent variable.
The degree of the spline fit.
The minimum number of knots to search. Defaults to 1.
The maximum number of knots to search. Defaults to 5.
The spline-fitting algorithm. Choices are "LS" for least-squares and "PS" for P-splines. Defaults to "LS."
The random search algorithm. Choices are "genetic" for a genetic algorithm and "golden" for a blind random search with golden section adjustment. Defaults to "genetic."
The criterion to be used for determining the number of knots. Choices are "GCV" for generalized cross-validation, "AIC" for the Akaike information criterion, "AICc" for corrected Akaike information criterion, "BIC" for Bayesian information criterion, "adjAIC" for an adjusted version of the Akaiki information criterion, and "adjGCV" for an adjusted version of generalized cross-validation. Defaults to "adjGCV."
The amount of penalty when AIC is used. Has no effect with criteria other than AIC. Defaults to 2.
The amount of penalty when adjGCV is used. Has no effect with criteria other than adjGCV. Defaults to 3.
The value of the initial seed. Defaults to 5.
The value of the initial stream to be used for parallel programming. Defaults to 0.
An object of class "freekt
" containing the following components:
A vector containing the x values.
A vector containing the y values.
The degree of the spline fit.
The value of the initial seed.
The value of the stream.
The optimum amount of penalty. This is automatically equal to 0 for freelsgen
and freelsgold
.
A vector containing the optimal knots.
The trace of the hat matrix for the optimal fit.
The value of generalized cross validation (GCV) for the optimal fit.)
The GSJS estimator, an estimator of the variance of the data.
The function call.
Eubank, R. (1999), Nonparametric Regression and Spline Smoothing, New York: Marcel Dekker, Inc., Second ed.
Spiriti, S., Eubank, R., Smith, P., Young, D., "Knot Selection for Least-Squares and Penalized Splines," Journal of Statistical Computation and Simulation, in press.
fitcriteria
for the fit criteria, freeknotfit
for the free-knot spline algorithms.
# NOT RUN {
x <- 0:30/30
truey <- x*sin(10*x)
set.seed(10556)
y <- truey + rnorm(31, 0, 0.2)
xy.freekt <- fit.search.numknots(x, y, degree = 2, minknot = 1, maxknot = 3, seed = 555)
plot.freekt(xy.freekt, xfit = 0:1000/1000)
# }
Run the code above in your browser using DataLab