btensor: btensor

Description Usage Arguments Details Value Author(s) Examples

Description

Tensor products of B-splines.

Usage

1
btensor(x, df = NULL, iknots = NULL, bknots, order)

Arguments

x

a list of variables to build B-spline transforms of. The tensor product of these B-splines will be returned.

df

degrees of freedom. a list of the degrees of freedom for each marginal.

iknots

a list of internal knots for each x. If omitted, the default is to place no internal knots for all x. If specified, the list needs to contain the internal knots for all x. If df and iknots are both given, the df will take precedence.

bknots

a list of boundary knots for each x. As with the iknots, if omitted the default will be to use the range of each x. If specified, the use must specify the bknots for each x.

order

a list of the order for each x; defaults to 4L for all x.

Details

The return form this function is the tensor product of the B-splines transformations for the given variables. Say we have variables X, Y, and Z to build the tensor product of. The columns of the returned matrix correspond to the column products of the three B-splines:

x1y1z1 x2y1z1 x3y1z1 x4y1z1 x1y2z1 x2y2z1 ... x4y4z4

for three fourth order B-splines with no internal knots. The columns of X cycle the quickest, followed by Y, and then Z. This would be the same result as model.matrix( ~ bsplines(X) : bsplines(Y) : bsplines(Z) + 0) .

See vignette("cpr-pkg", package = "cpr") for more details.

Value

A matrix with a class cpr_bt

Author(s)

Peter DeWitt dewittpe@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
tp <- with(mtcars,
           btensor(x = list(disp, hp, mpg),
                   iknots = list(numeric(0), c(100, 150), numeric(0)))
           )
tp
utils::str(tp)

# The equivalent matrix is could be generated as follows
tp2 <- model.matrix( ~ splines::bs(disp, intercept = TRUE) :
                       splines::bs(hp, knots = c(100, 150), intercept = TRUE) :
                       splines::bs(mpg, intercept = TRUE) + 0,
                    data = mtcars)

all.equal(tp2, unclass(tp), check.attributes = FALSE)

cpr documentation built on May 1, 2019, 10:46 p.m.