curfit.free.knot: free-knot splines

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Least squares splines with variable knots.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#curfit.free.knot(x, y, w=NULL, k = 3, g = 10, eps = 0.5e-3,
#                 prior = NULL, fixed = NULL, trace=1, ...)

#NOTE:  The following is required by CRAN rules that
# function names like "as.numeric" must follow the documentation
# standards for S3 generics, even when they are not.
# Please ignore the following line:
## S3 method for class 'free.knot'
curfit(x, y, w=NULL, k = 3, g = 10, eps = 0.5e-3,
                 prior = NULL, fixed = NULL, trace=1, ...)

Arguments

x

A data.frame, matrix, or numeric vector.

y

Optional numeric vector.

w

Observation weights.

k

degree of the spline; k=3 for cubic spline.

g

integer vector specifying the number(s) of knots to try.

This is ignored if 'prior' is provided.

If(length(g) == 1) g = 1:g. If(length(g)>1) g = seq(min(g), max(g)).

eps

weight on the reciprocal differences between successive knots:

penalty = eps*(diff(range(x))/(length(knots)+1)^2) * sigma0 * sum(1/diff(unique(knots)))

prior

initial values for the free knots

fixed

locations of fixed knots

trace

a number indicating the trace level. If 'g' is parsed as a vector, then with trace > 0, after a model for each g[i] is fit, the algorithm reports the number of knots, the variance of the residuals, and the z-score for the lag 1 autocorrelation of residuals.

For g[i] > 1, 'optim' is called with control=list(trace=trace-1).

...

Additional arguments used by curfit.

Details

1. If(!is.null(prior)) fit only a model with that number if free knots.

2. Otherwise, decode 'g' and fit one model for each level of 'g'.

3. Return the first model with a negative lag 1 autocorrelation, if any. Otherwise, return the last model fit.

Value

An object of class dierckx with the following components:

iopt

method used

m

length of 'x'

x

abscissa values

y

ordinate values

w

input weights

from

input from value

to

input to value

k

degree of the spline

s

input smoothing parameter

nest

Estimated number of knots

n

Actual number of knots

knots

Knot locations.

coef

b-Spline coefficients. Use coef.dierckx to extract.

fp

sum of squares residuals. Use deviance.dierckx to extract.

wrk

Work space. Do NOT modify before call to update.dierckx

lwrk

Length of wrk. Do NOT modify before call to update.dierckx

iwrk

Integer work space. Do NOT modify before call to update.dierckx

ier

Error code. Should always be zero.

message

convergence message or character(0)

g

Number of interior knots

method

input method value, e.g, 'ls' for least squares

periodic

logical: TRUE for a periodic spline

routine

Always 'curfit.default'

xlab

character x axis label for a plot

ylab

character y axis label for a plot

fits

This component is only present if(is.null(prior)). In that case it is a list with other objects of class 'dierckx' with attributes 'iopt', 'm', 'x', 'y', 'w', 'from', 'to', 'k', 's', 'nest', 'n', 'knots', 'coef', 'fp', 'wrk', 'lwrk', 'iwrk', 'ier', 'message', 'g', 'method', 'periodic', 'routine', 'xlab', 'ylab', as just described, one for each value of 'g' tested.

summary

a data.frame with the following columns:

  • gvector of the values of 'g' tested

  • sigma variance of the residuals = (sum of squares of residuals) / (degrees of freedom)

  • T z-score for the lag 1 autocorrelation of residuals = sqrt(length(x)-1) * (lag 1 autocorrelation of the residuals).

Author(s)

Sundar Dorai-Raj

References

Dierckx, P. (1991) Curve and Surface Fitting with Splines, Oxford Science Publications.

See Also

curfit, concon, spline, smooth.spline

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Skip this test on CRAN
# because it may exceed their 5 second limit
if(!CRAN()){

data(titanium)
titan10 <- with(titanium, curfit.free.knot(x, y))
#titan10.1 <- with(titanium, curfit.free.knot(x, y, k=1))
#titan10.1 <- with(titanium, curfit.free.knot(x, y, k=1, g=8, trace=1.1))
#titan10.1 <- with(titanium, curfit.free.knot(x, y, k=1,g=7:8,trace=1.1))
}

DierckxSpline documentation built on May 2, 2019, 6:30 p.m.