dlnm-internal {dlnm} | R Documentation |
Generate the basis functions for the space of predictor and lags. These functions are built for internal use only.
mkbasis(var, type="ns", df=1, degree=1, knots=NULL, bound=range(var), int=FALSE, cen=TRUE, cenvalue=mean(var)) mklagbasis(maxlag=0, type="ns", df=1, degree=1, knots=NULL, bound=c(0, maxlag), int=TRUE)
var |
a numeric vector of ordered observations. |
type |
type of basis. |
df |
dimension of the basis. They depend on knots or degree if provided. |
degree |
degree of polynomial. Used only for type equal to "bs" of "poly" . |
knots |
knots location for the basis. |
bound |
boundary knots. Used only for type equal to "ns" of "bs" . |
int |
logical. If TRUE , an intercept is included in the basis. |
cen |
logical. If TRUE , the basis functions are centered. |
cenvalue |
centering value. |
maxlag |
maximum lag. |
These two internal functions are called by crossbasis
to build the basis matrices for the two dimensions of predictor and lags. Even if they are not expected to be directly run by the users, they are included in the namespace of the package and therefore made accessible, with the intention to keep the process more transparent and give the opportunity to change or improve them.
mkbasis
applies a set basis functions on the vector of the predictor specified in var
. mklagbasis
calls mkbasis
to build the basis matrix for the space of lags. Basically, it creates a new vector 0:maxlag
(a vector of integers from 0 to the maximum lag allowed) and then apply the related basis functions. The functions for the 2 spaces are defined by the arguments above. See crossbasis
for additional information.
basis |
matrix of basis functions |
Additional values are returned that correspond to the arguments above, and explicitly give type
, df
, ddegree
, knots
, bound
, int
, varcen
, cenvalue
and maxlag
related to the corresponding basis.
Antonio Gasparrini, antonio.gasparrini@lshtm.ac.uk
Armstrong, B. Models for the relationship between ambient temperature and daily mortality. Epidemiology. 2006, 17(6):624-31.
# natural cubic spline with a knot at 3 basis.var <- mkbasis(1:5, knots=3) basis.var # quadratic spline selected by df, automatic knots location mkbasis(1:5, type="bs", df=4, degree=2) # linear centered at 4 mkbasis(1:5, type="lin", cenvalue=4) # polynomial with degree 3, with intercept mklagbasis(maxlag=5, type="poly", degree=3) # integer mklagbasis(maxlag=5, type="integer") # threshold-type: double and single threshold or piecewise mkbasis(1:5, type="dthr", knots=c(2,3)) mkbasis(1:5, type="hthr", knots=3) mkbasis(1:5, type="hthr", knots=c(2,3)) # the intercept: strata defined by 2 cut-off points mklagbasis(maxlag=10, type="strata", knots=c(4,7)) mklagbasis(maxlag=10, type="strata", knots=c(4,7), int=FALSE) # centering: polynomial mkbasis(0:10, type="poly", degree=3) mkbasis(0:10, type="poly", degree=3, cen=FALSE) ### See the vignette 'dlnmOverview' for a detailed explanation of this example