Learn R Programming

dlnm (version 1.4.1)

dlnm-internal: Internal functions for package dlnm

Description

Generate different types of basis matrices for the space of predictor and lags. These functions are called internally by other functions and are not meant to be directly run by the users.

Usage

mkbasis(x, type="ns", df=1, degree=1, knots=NULL,
	bound=range(x),int=FALSE, cen=TRUE, cenvalue=mean(x))

mklagbasis(maxlag=0, type="ns", df=1, degree=1, knots=NULL,
	bound=c(0, maxlag), int=TRUE)

Arguments

x
the predictor variable. Missing values are allowed.
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.

Value

  • basismatrix of basis functions
  • Additional values are returned that correspond to the arguments above, and explicitly give type, df, degree, knots, bound, int, varcen, cenvalue and maxlag related to the corresponding basis.

Details

mkbasis applies a set basis functions to the predictor vector x. 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 applies the related basis functions. The basis functions for each dimension are defined by the arguments above. See crossbasis for additional information on the specific bases. These two functions are called by crossbasis to build the basis matrices for the two dimensions of predictor and lags in DLNMs. . 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. For a detailed illustration of the use of the functions, see: vignette("dlnmOverview")

References

Gasparrini A. Distributed lag linear and non-linear models in R: the package dlnm. Journal of Statistical Software. 2011; 43(8):1-20. URL http://www.jstatsoft.org/v43/i08/. Gasparrini A., Armstrong, B.,Kenward M. G. Distributed lag non-linear models. Statistics in Medicine. 2010; 29(21):2224-2234.

Examples

Run this code
# NATURAL CUBIC SPLINE WITH A KNOT AT 3
basis.var <- mkbasis(1:5, knots=3)
basis.var

# QUADRATIC SPLINE SELECTED BY DF, AUTOMATIC KNOT 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

Run the code above in your browser using DataLab