Learn R Programming

dlnm (version 0.4.1)

dlnm-internal: Internal functions for package dlnm

Description

Generate the basis functions for the space of predictor and lags. These functions are built for internal use only.

Usage

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)

Arguments

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.

Value

  • basismatrix 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.

Details

These functions are called by crossbasis in order to build the related cross-basis functions. See crossbasis for further details.

References

Armstrong, B. Models for the relationship between ambient temperature and daily mortality. Epidemiology. 2006, 17(6):624-31.

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 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

Run the code above in your browser using DataLab