periodicSpline
Create a Periodic Interpolation Spline
Description
Creates a periodic interpolation spline.
Usage
periodicSpline(obj1, obj2, knots, period = 2 * pi, ord = 4)
## Default S3 method:
periodicSpline(obj1, obj2, knots, period = 2 * pi, ord = 4)
## S3 method for class 'formula':
periodicSpline(obj1, obj2, knots, period = 2 * pi, ord = 4)
Arguments
obj1 |
a numeric vector or a formula with the form of "y~x".
|
obj2 |
a numeric vector with the same length as obj1,
or an optional data frame to evaluate the terms when obj1 is a formula.
When obj1 is a formula and obj2 is missing, the sys.parent(1) is
used as evaluation parent frame.
|
knots |
a numeric vector. Used to design interpolation spline.
|
period |
an optional value specifying the period for a periodic interpolation spline.
|
ord |
a positive integer. Must be bigger than 2, and
at most the number of knots of obj1.
|
Details
The elements of
obj1 must be distinct in the function
periodicSpline.default.
- If knots is missing, knots is composed by
c(x[(lenx - (ord - 2)):lenx] - period, x, x[1L:ord] + period)
- If knots is not missing, period is rewritten by
knots[length(knots) - ord + 1] - knots[1L].
The range between the first value and the last value of
obj1 should be in one period.
Value
returns a list object of class
c("pbSpline", "bSpline", "spline") that contains
four components:
- "knots"
- "coefficients"
- "order"
- "period" with the attribute "formula"
See Also
Examples
qtr <- c(1, 2, 3, 4)
sales <- c(101, 102, 113, 104)
# fit a smooth seasonal pattern to sales
pS <- periodicSpline(qtr, sales, period = 4)
# interpolate/extrapolate to new times
predict(pS, seq(3,7,by=1/4))