rcs: Calculate basis terms for restricted cubic splines

Description Usage Arguments Value References Examples

Description

The rcs function calculates the basis terms for the restricted cubic splines as defined in Royston and Parmar (2002). The drcs function calculates the corresponding first derivative of the basis terms.

Usage

1
2
3
rcs(x, df = 3, iknots = NULL, bknots = NULL)

drcs(x, df = 3, iknots, bknots = NULL)

Arguments

x

A numeric vector for which to evaluate the spline basis terms.

df

Integer specifying the degrees of freedom for the splines. If the iknots argument is NULL, then df - 1 internal knots are placed at equally spaced percentiles of x.

iknots

An optional vector of internal knot positions. Note that the df argument is ignored if iknots is specified.

bknots

A numeric vector of length 2 specifying the position of the lower and upper boundary knots, beyond which a linearity restriction is enforced. If NULL, then the boundary knots are set to the minimum and maximum of x.

Value

A matrix, with dimension length(x) by df, where df is one greater than the number of internal knots.

References

Royston P, Parmar MKB. Flexible parametric proportional-hazards and proportional-odds models for censored survival data, with application to prognostic modelling and estimation of treatment effects. Statistics in Medicine. 2002;21:2175–2197. doi: 10.1002/sim.1203

Examples

1
2
3
4
5
6
7
8
times <- runif(40,0,10)

rcs1 <- rcs(times, df = 2) # one internal knot at median
rcs2 <- rcs(times, iknots = c(2,5,8))
rcs3 <- rcs(times, iknots = c(2,5), bknots = c(1,8))

drcs1 <- drcs(times, df = 2)
drcs2 <- drcs(times, iknots = c(2,5,8))

csetraynor/rstanhaz documentation built on May 9, 2019, 8:14 a.m.