genspline: Generates spline basis matrices for fitting to dose-response...

gensplineR Documentation

Generates spline basis matrices for fitting to dose-response function

Description

Generates spline basis matrices for fitting to dose-response function

Usage

genspline(
  x,
  spline = "bs",
  knots = 1,
  degree = 1,
  max.dose = 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 ("ls"), natural cubic spline ("ns"), or B-spline ("bs").

knots

The number/location of internal knots. If a single integer is given it indicates the number of knots (they will be equally spaced across the range of doses for each agent). If a numeric vector is given it indicates the quantiles of the knots as a proportion of the maximum dose in the dataset. For example, if the maximum dose in the dataset is 100mg/d, knots=c(0.1,0.5) would indicate knots should be fitted at 10mg/d and 50mg/d.

degree

a positive integer giving the degree of the polynomial from which the spline function is composed (e.g. degree=3 represents a cubic spline).

max.dose

A number indicating the maximum dose between which to calculate the spline function.

boundaries

A positive numeric vector of length 2 that represents the doses 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 x. The default (boundaries=NULL) is the range of x.

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 cubic spline with 3 knots at selected quantiles
genspline(x, spline="ns", knots=c(0.1, 0.5, 0.7))

# Generate a piecewise linear spline with 3 equally spaced knots
genspline(x, spline="ls", knots=3)


MBNMAdose documentation built on Aug. 8, 2023, 5:11 p.m.