Learn R Programming

freeknotsplines (version 1.0.1)

fit.search.numknots: Perform a Search on the Number of Knots and Fit Free-Knot Splines To Data Using the Optimal Number of Knots

Description

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.

Usage

fit.search.numknots(x, y, degree, minknot = 1, maxknot = 5, 
                   alg = "LS", search = "genetic",
                   knotnumcrit = "adjGCV", k = 2, d = 3, seed = 5,
                   stream = 0)

Arguments

x

A vector containing the values of the independent variable.

y

A vector containing the values of the dependent variable.

degree

The degree of the spline fit.

minknot

The minimum number of knots to search. Defaults to 1.

maxknot

The maximum number of knots to search. Defaults to 5.

alg

The spline-fitting algorithm. Choices are "LS" for least-squares and "PS" for P-splines. Defaults to "LS."

search

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."

knotnumcrit

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."

k

The amount of penalty when AIC is used. Has no effect with criteria other than AIC. Defaults to 2.

d

The amount of penalty when adjGCV is used. Has no effect with criteria other than adjGCV. Defaults to 3.

seed

The value of the initial seed. Defaults to 5.

stream

The value of the initial stream to be used for parallel programming. Defaults to 0.

Value

An object of class "freekt" containing the following components:

x

A vector containing the x values.

y

A vector containing the y values.

degree

The degree of the spline fit.

seed

The value of the initial seed.

stream

The value of the stream.

lambda

The optimum amount of penalty. This is automatically equal to 0 for freelsgen and freelsgold.

optknot

A vector containing the optimal knots.

tracehat

The trace of the hat matrix for the optimal fit.

GCV

The value of generalized cross validation (GCV) for the optimal fit.)

GSJS

The GSJS estimator, an estimator of the variance of the data.

call

The function call.

References

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.

See Also

fitcriteria for the fit criteria, freeknotfit for the free-knot spline algorithms.

Examples

Run this code
# 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