Learn R Programming

splinetrials (version 0.1.1)

time_spline: Create Natural Cubic Spline Approximations for Continuous Time

Description

Accepts or constructs a natural cubic spline basis for continuous time and yields a matrix of approximations for time according to that basis.

Usage

time_spline(
  time,
  df = NULL,
  ...,
  basis = time_spline_basis(time, df = df, ...)
)

Value

Matrix with the same dimensions as basis. Contains basis as an attribute.

Arguments

time

A numeric vector of values.

df, ...

Only used if basis is left as the default. Passed to time_spline_basis() (which passes all arguments to splines::ns()) to calculate the spline basis.

basis

Spline basis for which to create approximations of time. Defaults to time_spline_basis(time, df = df, ...).

Details

time_spline() is primarily useful because it can use one step to create the spline basis from time and then re-input time into the spline basis to obtain the spline approximations. Alternatively, it can calculate predictions from a basis supplied to the basis argument.

Examples

Run this code
time_spline(Theoph$Time, df = 3)

# Or, compute the spline basis beforehand, and then pass it to time_spline()
basis <-
  splines::bs(Theoph$Time, df = 3, Boundary.knots = c(0, max(Theoph$Time)))

time_spline(Theoph$Time, basis = basis)

Run the code above in your browser using DataLab