Generates a basis matrix for representing the family of piecewise-cubic
splines with the specified sequence of interior knots, and the boundary
conditions.
USAGE:
ns(x, df, knots, intercept=F)
REQUIRED ARGUMENTS:
x:
the predictor variable.
OPTIONAL ARGUMENTS:
df:
degrees of freedom. One can supply df rather than knots; ns then
chooses df-1-intercept knots at suitably chosen quantiles of x.
knots:
breakpoints that define the spline.
The default is no knots; together with the natural boundary
conditions this results in a
basis for linear regression on x.
Typical values are the mean or median for one knot, quantiles for
more knots.
intercept:
if TRUE, an intercept is included in the basis; default is FALSE.
VALUE:
a matrix of dimension length(x) * df where either df was supplied or
if knots were supplied, df = length(knots) + 1 + intercept.
DETAILS:
This function generates a basis matrix for representing the family of
piecewise-cubic splines with the specified sequence of interior knots,
and the natural boundary conditions.
These enforce the constraint that the function is linear beyond
the boundary knots, which are taken to be at the extremes of the data.
A primary use is in modeling formula to directly specify a natural
spline term in a model.
REFERENCES:
de Boor, C. (1978).
A Practical Guide to Splines.
Berlin: Springer Verlag.
Cheney, W., Kincaid, D. (1985).
Numerical Mathematics and Computing, Second edition.
New York: Brooks/Cole Publishing Co.