tensor.prod.model.matrix {mgcv} R Documentation

## Row Kronecker product/ tensor product smooth construction

### Description

Produce model matrices or penalty matrices for a tensor product smooth from the model matrices or penalty matrices for the marginal bases of the smooth (marginals and results can be sparse). The model matrix construction uses row Kronecker products.

### Usage

tensor.prod.model.matrix(X)
tensor.prod.penalties(S)
a%.%b


### Arguments

 X a list of model matrices for the marginal bases of a smooth. Items can be class "matrix" or "dgCMatrix", but not a mixture of the two. S a list of penalties for the marginal bases of a smooth. a a matrix with the same number of rows as A. b a matrix with the same number of rows as B.

### Details

If X[], X[] ... X[[m]] are the model matrices of the marginal bases of a tensor product smooth then the ith row of the model matrix for the whole tensor product smooth is given by X[][i,]%x%X[][i,]%x% ... X[[m]][i,], where %x% is the Kronecker product. Of course the routine operates column-wise, not row-wise!

A%.%B is the operator form of this ‘row Kronecker product’.

If S[], S[] ... S[[m]] are the penalty matrices for the marginal bases, and I[], I[] ... I[[m]] are corresponding identity matrices, each of the same dimension as its corresponding penalty, then the tensor product smooth has m associate penalties of the form:

S[]%x%I[]%x% ... I[[m]],

I[]%x%S[]%x% ... I[[m]]

...

I[]%x%I[]%x% ... S[[m]].

Of course it's important that the model matrices and penalty matrices are presented in the same order when constructing tensor product smooths.

### Value

Either a single model matrix for a tensor product smooth (of the same class as the marginals), or a list of penalty terms for a tensor product smooth.

### Author(s)

Simon N. Wood simon.wood@r-project.org

### References

Wood, S.N. (2006) Low rank scale invariant tensor product smooths for Generalized Additive Mixed Models. Biometrics 62(4):1025-1036

te, smooth.construct.tensor.smooth.spec

### Examples

require(mgcv)
## Dense row Kronecker product example...
X <- list(matrix(0:3,2,2),matrix(c(5:8,0,0),2,3))
tensor.prod.model.matrix(X)
X[]%.%X[]

## sparse equivalent...
Xs <- lapply(X,as,"dgCMatrix")
tensor.prod.model.matrix(Xs)
Xs[]%.%Xs[]

S <- list(matrix(c(2,1,1,2),2,2),matrix(c(2,1,0,1,2,1,0,1,2),3,3))
tensor.prod.penalties(S)
## Sparse equivalent...
Ss <- lapply(S,as,"dgCMatrix")
tensor.prod.penalties(Ss)


[Package mgcv version 1.9-0 Index]