equalknots {dlnm}R Documentation

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)

[Package dlnm version 2.4.7 Index]