Restricted Cubic Spline Design Matrix
Computes matrix that expands a single variable into the terms needed to
fit a restricted cubic spline (natural spline) function using the
truncated power basis. Two normalization options are given for somewhat
reducing problems of ill-conditioning. The antiderivative function can
be optionally created. If knot locations are not given, they will be
estimated from the marginal distribution of
rcspline.eval(x, knots, nk=5, inclx=FALSE, knots.only=FALSE, type="ordinary", norm=2, rpm=NULL)
- a vector representing a predictor variable
- knot locations. If not given, knots will be estimated using default
x. For 3-5 knots, the outer quantiles used are .05 and .95. For
nk>5, the outer quantiles are .025 and .975. The knots are equally spaced between th
- number of knots. Default is 5. The minimum value is 3.
- set to
xas the first column of the returned matrix
- return the estimated knot locations but not the expanded matrix
"ordinary"to fit the function,
"integral"to fit its anti-derivative.
0to use the terms as originally given by Devlin and Weeks (1986),
1to normalize non-linear terms by the cube of the spacing between the last two knots,
2to normalize by the square of the spacing between the first
- If given, any NAs in
xwill be replaced with the value
rpmafter estimating any knot locations.
knots.only=TRUE, returns a vector of knot locations. Otherwise returns a matrix with
inclx=TRUE) followed by
nk-2nonlinear terms. The matrix has an attribute
knotswhich is the vector of knots used.
Devlin TF and Weeks BJ (1986): Spline functions for logistic regression modeling. Proc 11th Annual SAS Users Group Intnl Conf, p. 646--651. Cary NC: SAS Institute, Inc.
x <- 1:100 rcspline.eval(x, nk=4, inclx=TRUE) #lrm.fit(rcspline.eval(age,nk=4,inclx=TRUE), death)