equalknots: Define Knots at Equally-Spaced Values

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/equalknots.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
### 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)

Example output

This is dlnm 2.3.6. For details: help(dlnm) and vignette('dlnmOverview').
[1] 20 20 20
[1] 20 20 20
[1] 20 20
[1] 20 20 20 20
[1] 20 20 20
[1] 20 20

dlnm documentation built on Oct. 7, 2021, 5:09 p.m.