Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

equalknots

Define Knots at Equally-Spaced Values


Description

This function defines the position of knot or cut-off values at equally-spaced values for spline or strata functions, respectively.

Usage

equalknots(x, nk=NULL, fun="ns", df=1, degree=3, intercept=FALSE)

Arguments

x

a vector variable.

nk

number of knots or cut-offs.

fun

character scalar with the name of the function for which the knots or cut-offs must be created. See Details below.

df

degree of freedom.

degree

degree of the piecewise polynomial. Only for fun="bs".

intercept

logical. If an intercept is included in the basis function.

Details

The number of knots is set with the argument nk, or otherwise determined by the choice of function and number of degrees of freedom through the arguments fun and df. Specifically, the number of knots is set to df-1-intercept for "ns", df-degree-intercept for "bs", or df-intercept for "strata".

Value

A numeric vector of knot or cut-off values.

Author(s)

Antonio Gasparrini <antonio.gasparrini@lshtm.ac.uk>

See Also

logknots for placing the knots at equally-spaced log values. crossbasis to generate cross-basis matrices.

See dlnm-package for an introduction to the package and for links to package vignettes providing more detailed information.

Examples

### setting 3 knots for range 0-20
equalknots(20, 3)

### setting knots and cut-offs for different functions
equalknots(20, fun="ns", df=4)
equalknots(20, fun="bs", df=4, degree=2)
equalknots(20, fun="strata", df=4)

### with and without without intercept
equalknots(20, fun="ns", df=4)
equalknots(20, fun="ns", df=4, intercept=TRUE)

dlnm

Distributed Lag Non-Linear Models

v2.4.5
GPL (>= 2)
Authors
Antonio Gasparrini [aut, cre], Ben Armstrong [aut], Fabian Scheipl [ctb]
Initial release
2021-03-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.