bs(x, df, knots, degree=3, intercept=FALSE, Boundary.knots, derivs)
df rather than
knots;
bs then
chooses
df-degree-intercept knots (not including boundary knots) at suitable quantiles of
x.
This argument is ignored if
knots is supplied.
NULL, which results in a
basis for ordinary polynomial regression (if
df is not given). Typical values
are the mean or median for one knot, quantiles for more knots. See also
Boundary.knots.
TRUE, an intercept is included in the basis; default is
FALSE.
knots and
Boundary.knots are supplied,
the basis parameters do not depend on
x.
Alternately, if
Boundary.knots is
TRUE, then
knots includes both
the internal knots and boundary points.
Data can extend beyond
Boundary.knots.
x; if supplied then derivatives of the
basis functions are returned.
length(x) * df,
where
df = length(knots) + degree + intercept.
(Here
length(knots) does not count boundary knots.)
Attributes are returned that correspond to the arguments to
bs and
explicitly give the
knots,
Boundary.knots, etc., for use by
predict.bs
.
The
bs function is based on the function
spline.des
written by Douglas Bates.
It generates a basis matrix for representing the family of
piecewise polynomials with the specified interior knots and degree,
evaluated at the values of
x.
A primary use is in modeling formulas to directly specify
a piecewise polynomial term in a model.
Beware of making predictions with new
x values.
Results will differ unless the
knots and
Boundary.knots
are the same.
predict(object, newx)
uses the same values
when object is the direct output of
bs, but
not when
object is the output of a modeling function like
lm.
It is best to explicitly specify
knots and
Boundary.knots
when using modeling functions for prediction.
For arithmetic involving
intercept,
FALSE==0
and
TRUE==1
.
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.
lm(y ~ bs(age, 4) + bs(income, 4)) # an additive model fit <- lm(y ~ bs(age, knots=c(20,30), B=c(0,100))) predict(fit, new.age) # safe prediction because all knots supplied x <- -10:110 b <- bs(x, knots=c(20,30), B=c(0,100)) b <- bs(x, knots=c(0,20,30,100), Bound=T) # equivalent matplot(x, b, type="l") matplot(x, predict(b, x, derivs=1), type="l")