genspline {MBNMAtime} | R Documentation |
Generates spline basis matrices for fitting to time-course function
Description
Generates spline basis matrices for fitting to time-course function
Usage
genspline(
x,
spline = "bs",
knots = 1,
degree = 1,
max.time = max(x),
boundaries = NULL
)
Arguments
x |
A numeric vector indicating all time points available in the dataset |
spline |
Indicates the type of spline function. Can be either a piecewise linear spline ( |
knots |
The number/location of knots. If a single integer is given it indicates the number of knots (they will
be equally spaced across the range of time-points). If a numeric vector is given it indicates the quantiles of the knots as
a proportion of the maximum study follow-up in the dataset. For example, if the maximum follow-up time in the dataset
is 10 months, |
degree |
a positive integer giving the degree of the polynomial from which the spline function is composed
(e.g. |
max.time |
A number indicating the maximum time between which to calculate the spline function. |
boundaries |
A positive numeric vector of length 2 that represents the time-points at which to anchor the B-spline or natural
cubic spline basis matrix. This allows data to extend beyond the boundary knots, or for the basis parameters to not depend on |
Value
A spline basis matrix with number of rows equal to length(x)
and the number of columns equal to the number
of coefficients in the spline.
Examples
x <- 0:100
genspline(x)
# Generate a quadratic B-spline with 1 equally spaced internal knot
genspline(x, spline="bs", knots=2, degree=2)
# Generate a natural spline with 2 knots at selected quantiles
genspline(x, spline="ns", knots=c(0.1, 0.5))
# Generate a piecewise linear spline with 3 equally spaced knots
genspline(x, spline="ls", knots=3)