rcspline.eval: Restricted Cubic Spline Design Matrix In harrelfe/Hmisc: Harrell Miscellaneous

Description

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 x.

Usage

 1 2 3 rcspline.eval(x, knots, nk=5, inclx=FALSE, knots.only=FALSE, type="ordinary", norm=2, rpm=NULL, pc=FALSE, fractied=0.05)

Arguments

 x a vector representing a predictor variable knots knot locations. If not given, knots will be estimated using default quantiles of x. For 3 knots, the outer quantiles used are 0.10 and 0.90. For 4-6 knots, the outer quantiles used are 0.05 and 0.95. For \code{nk}>6, the outer quantiles are 0.025 and 0.975. The knots are equally spaced between these on the quantile scale. For fewer than 100 non-missing values of x, the outer knots are the 5th smallest and largest x. nk number of knots. Default is 5. The minimum value is 3. inclx set to TRUE to add x as the first column of the returned matrix knots.only return the estimated knot locations but not the expanded matrix type "ordinary" to fit the function, "integral" to fit its anti-derivative. norm 0 to use the terms as originally given by Devlin and Weeks (1986), 1 to normalize non-linear terms by the cube of the spacing between the last two knots, 2 to normalize by the square of the spacing between the first and last knots (the default). norm=2 has the advantage of making all nonlinear terms beon the x-scale. rpm If given, any NAs in x will be replaced with the value rpm after estimating any knot locations. pc Set to TRUE to replace the design matrix with orthogonal (uncorrelated) principal components computed on the scaled, centered design matrix fractied If the fraction of observations tied at the lowest and/or highest values of x is greater than or equal to fractied, the algorithm attempts to use a different algorithm for knot finding based on quantiles of x after excluding the one or two values with excessive ties. And if the number of unique x values excluding these values is small, the unique values will be used as the knots. If the number of knots to use other than these exterior values is only one, that knot will be at the median of the non-extreme x. This algorithm is not used if any interior values of x also have a proportion of ties equal to or exceeding fractied.

Value

If knots.only=TRUE, returns a vector of knot locations. Otherwise returns a matrix with x (if inclx=TRUE) followed by \code{nk}-2 nonlinear terms. The matrix has an attribute knots which is the vector of knots used. When pc is TRUE, an additional attribute is stored: pcparms, which contains the center and scale vectors and the rotation matrix.

References

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.