Build a design matrix for a natural spline basis.

natSplineX(date, origin = NULL, knots, boundaryKnots, constant = TRUE)

Arguments

date

A vector with class "Date" or a vector that can be coerced to the "Date" class, typically an unambiguous character vector.

origin

Optional vector of length 1 with class "Date" or character that can be coerced to this class. Gives the origin for the transformation of dates into numeric values. The default value is 1970-01-01, see Date.

knots

A vector with class "Date" or a vector that can be coerced to the "Date" class, giving the location of the knots as in ns.

boundaryKnots

A vector with class "Date" or a vector that can be coerced to the "Date" class, giving the location of the boundary knots in ns.

constant

Logical passed as intercept to ns.

Value

An object with class "bts" inheriting from "matrix". This is essentially a numeric matrix having the value of the basis functions as its columns. Each row corresponds to an element of the given date vector. By convention, the columns are named "ns1", "ns2", ... The number of colums is equal to df is provided or if knots was supplied, to length(knots) + 1 + constant.

Details

The design matrix contains a basis to represent a natural spline with possibly chosen knots if needed. By default the boundary knots are chosen as the range of the numeric translation of date. The basis generates a space of cubic splines with their second order derivative vanishing at the two boundary knots. Therefore, the splines behave as a polynomials of degree one outside of the boundary knots.

See also

The ns function used to compute the basis, and breaksX, polynomX for alternative bases.

Examples

date <- as.Date(sprintf("%4d-01-01", 1921:2020))
X1 <- natSplineX(date = date, knots = "1950-01-01",
                 boundaryKnots = c("1920-01-01", "2021-01-01"))
plot(X1)