add_splines: Add spline terms to a data frame

Description Usage Arguments Value Knot Locations Examples

View source: R/add_splines.R

Description

Adds spline terms calculated via Hmisc::rcspline.eval() to a data frame.

Usage

1
add_splines(data, variable, knots = NULL, nk = 5, norm = 2, new_names = NULL)

Arguments

data

a data frame

variable

name of column in data

knots

knot locations. If not given, knots will be estimated using default quantiles of x. For 3 knots, the outer quantiles used are 0.10 and 0.90. For 4-6 knots, the outer quantiles used are 0.05 and 0.95. For \code{nk}>6, the outer quantiles are 0.025 and 0.975. The knots are equally spaced between these on the quantile scale. For fewer than 100 non-missing values of x, the outer knots are the 5th smallest and largest x.

nk

number of knots. Default is 5. The minimum value is 3.

norm

0 to use the terms as originally given by Devlin and Weeks (1986), 1 to normalize non-linear terms by the cube of the spacing between the last two knots, 2 to normalize by the square of the spacing between the first and last knots (the default). norm=2 has the advantage of making all nonlinear terms beon the x-scale.

new_names

Optionally specify names of new spline columns

Value

data frame

Knot Locations

Knot locations are returned in attr(data[[variable]], "knots")

Examples

1
2
trial %>%
  add_splines(age)

ddsjoberg/hotfun documentation built on Dec. 12, 2021, 3:41 a.m.