Learn R Programming

peRiodiCS (version 0.5.0)

cs_per: Generate design matrix for periodic cubic splines

Description

Generate design matrix for periodic cubic splines.

Usage

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

Run this code
# NOT RUN {
# 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)

# }

Run the code above in your browser using DataLab