Learn R Programming

brokenstick (version 1.1.0)

make_basis: Create linear splines basis

Description

This function creates the basis function of a second-order (linear) splines at a user-specific set of break points.

Usage

make_basis(
  x,
  knots = NULL,
  boundary = range(x),
  degree = 1L,
  warn = TRUE,
  knotnames = TRUE
)

Arguments

x

a data.frame with one column

knots

a vector of internal knots, excluding boundary knots

boundary

vector of external knots

degree

the degree of the spline. The broken stick model requires linear splines, so the default is degree = 1. Setting degree = 0 yields (crisp) dummy coding, and one column less than for degree = 1.

warn

a logical indicating whether warnings from splines::bs() should be given.

knotnames

Should the column names be the knots?

Value

A matrix with length(x) rows and length(breaks) columns, with some extra attributes described by bs().

Examples

Run this code
# NOT RUN {
knots <- c(58, 64, 68, 72)
d1 <- make_basis(data.frame(hgt = women$height), knots = knots)
d0 <- make_basis(data.frame(hgt = women$height), knots = knots, degree = 0)
# }

Run the code above in your browser using DataLab