These functions define a smooth class for bi-dimensional cross-basis splines for penalized distributed lag linear (DLMs) and non-linear (DLNMs) models. The functions are not supposed to be called directly, and the class is usually specified via terms like s(X,L,bs="cb",...)
in the formula of the gam
function of the package mgcv.
smooth.construct.cb.smooth.spec(object, data, knots)Predict.matrix.cb.smooth(object, data)
a smooth specification object, usually generated by a term s(X,L,bs="cb",...)
.
a list containing just the data (including any by variable) required by this term, with names corresponding to object$term
.
a list containing any knots supplied for basis setup --- in same order and with same names as data. It is usually NULL
.
The smooth constructor function returns an object of classes "cb.smooth"
and "tensor.smooth"
. Specifically, a list with a similar structure of that returned by the smooth constructor for tensor product smooths
(see also te
).
The Predict.matrix
function return a cross-basis matrix evaluated at specific values used for prediction.
These functions embed tools available in the packages dlnm and mgcv to perform penalized DLMs and DLNMs. This represent the internal method to perform such models (see Notes below). Specifically, the models are fitted by including a term s(X,L,bs="cb",...)
, defining a class "cb"
for bi-dimensional cross-basis splines, in the formula of the gam
function. The constructor function for this class turns this smooth terms into a smooth specification object, which includes the cross-basis matrix (see crossbasis
) and the penalty matrices for the two spaces of predictor and lags used in model fitting. Then, crosspred
uses the predict matrix function for the "cb"
class to obtain predictions, and a graphical representation can be obtained by standard plotting functions
, similary to unpenalized models.
The first two arguments X
and L
in s
represent a matrix of exposure histories and a matrix of lags. The former, also used in crossbasis
, needs to be defined directly even with time series data by lagging the exposure series. The matrix L
must have the same dimensions of X
, with identical rows representing the sequence of lags. The other arguments of s
have the same meaning: in particular, k
(default to 10), fx
(default to FALSE
) and sp
(default to NULL
) can be provided for each marginal basis as vectors of length 2, and similarly m
can be provided as a list (see also te
). No by
argument is allowed.
Extra information can be included in the argument xt
of s
, which accepts a single object or a list of objects. First, an object bs
(a vector of length 1 or 2) can be used to specify the smoother for each marginal dimension, with current options restricted to "ps"
(P-splines
, used by default) and/or "cr"
(cubic regression splines
). Second, list objects argvar
and arglag
can be used to build the marginal bases for predictor and lags by calling other functions (see the same arguments in crossbasis
). In particular, these can be used for a more flexible specification of penalized functions (using ps
or cr
) or for using unpenalized functions for one marginal basis, thus limiting the penalization to one of the two dimensions. Third, the object addSlag
can contain a matrix or vector (or list of matrices and/or vectors) defining additional penalties on the lag structure (see cbPen
).
Gasparrini A, Scheipl F, Armstrong B, Kenward MG. A penalized framework for distributed lag non-linear models. Biometrics. 2017;73(3):938-948. [freely available here]
Wood S. N. Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press, 2006.
Smooth constructors for P-splines
and cubic regression splines
in mgcv. ps
and cr
for the same functions available in dlnm. cbPen
for defining tensor-type bi-dimensional penalties in DLNMs.
See dlnm-package
for an introduction to the package and for links to package vignettes providing more detailed information.
# NOT RUN {
# to be added soon
# }
Run the code above in your browser using DataLab