Functions for Generating Periodic Curves

Functions for generating variants of curves: restricted cubic spline, periodic restricted cubic spline, periodic cubic spline. Periodic splines can be used to model data that has periodic nature / seasonality.


Travis-CI Build Status

Code for periodic versions of cubic splines and restricted cubic splines. The functions transform a numeric (time) variable x into a new basis, to model with either a periodic variant of cubic splines or periodic restricted cubic spline.

Install from GitHub with:

library(devtools)
install_github("crtahlin/peRiodiCS")

Example models for different variants:

data("viral_east_mediteranean")

# calculate location of knots to use
Knots <- Hmisc::rcspline.eval(x = viral_east_mediteranean$EpiWeek,
                              nk = 5, knots.only = TRUE)
                       
### RCS - restricted cubic splines (non-periodic, just for reference) #########
# model viral infections vs weeks
model_rcs <- glm(RSV ~ Hmisc::rcspline.eval(EpiWeek, inclx = TRUE, knots = Knots), data = viral_east_mediteranean)

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

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

# plot model (with many points, to make it smooth)
plot_per_mod(Model = model_rcs_per, XvarName = "EpiWeek", Smooth = TRUE)
                                  
### periodic CS (cubic spline) ###############################################
# model viral infections vs weeks
model_cs_per <- 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_cs_per, XvarName = "EpiWeek", Smooth = TRUE)

News

peRiodiCS 0.5.0

First release to CRAN.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("peRiodiCS")

0.5.0 by Crt Ahlin, 10 months ago


Report a bug at https://github.com/crtahlin/peRiodiCS/issues


Browse source code at https://github.com/cran/peRiodiCS


Authors: Crt Ahlin [aut, cre] , Lara Lusa [aut]


Documentation:   PDF Manual  


GPL-3 license


Imports graphics, Hmisc, rms

Suggests testthat


See at CRAN