cs_per: Generate design matrix for periodic cubic splines

Description Usage Arguments Examples

View source: R/cs_per.R

Description

Generate design matrix for periodic cubic splines.

Usage

1
2
cs_per(x, knots = NULL, nk = 5, xmax = max(x, na.rm = TRUE),
  xmin = min(x, na.rm = TRUE))

Arguments

x

numerical x values to transform to new basis

knots

vector with locations of the knots of the spline

nk

number of knots, used only if the knots are not specified, overridden otherwise

xmax

value of the (theoretical) minimum of x

xmin

value of the (theoretical) maximum of x

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# load example data; see help("viral_east_mediteranean")
data("viral_east_mediteranean")

# calculate location of knots to use
Knots <- 
 Hmisc::rcspline.eval(x = viral_east_mediteranean$EpiWeek,
                      nk = 5, knots.only = TRUE)

# model viral infections vs weeks
model <- glm(RSV ~ cs_per(EpiWeek, knots = Knots), data = viral_east_mediteranean)

# plot model (with many points, to make it smooth)
plot_per_mod(Model = model, XvarName = "EpiWeek", Smooth = TRUE)

peRiodiCS documentation built on May 2, 2019, 11:10 a.m.