Help for package peRiodiCS (original) (raw)

Type: Package
Title: Functions for Generating Periodic Curves
Version: 0.5.0
Date: 2018-07-02
Description: 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.
License: GPL-3
BugReports: https://github.com/crtahlin/peRiodiCS/issues
Depends: R (≥ 2.10)
Imports: graphics, Hmisc, rms
Suggests: testthat
LazyData: true
RoxygenNote: 6.0.1
NeedsCompilation: no
Packaged: 2018-07-02 15:22:31 UTC; crtah
Author: Crt Ahlin [aut, cre], Lara Lusa [aut]
Maintainer: Crt Ahlin crt.ahlin@gmail.com
Repository: CRAN
Date/Publication: 2018-07-05 09:20:07 UTC

Basis for restricted cubic splines

Description

Function that derives the restricted cubic splines for a value/vector of values, given the knots; obtains exactly the same results as the rcs function included in the rms package.

Usage

b_rcs(x, knots, inclx = FALSE)

Arguments

x numerical vector
knots vector specifying the knot locations
inclx logical, if TRUE returns also the x vector

Derive first derivatives of RCS

Description

function that derives the first derivative of the restricted cubic splines for a value/vector of values, given the knots

Usage

b_rcs_prime(x, knots)

Arguments

x vector of values
knots vector of knot locations

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

# 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)


Plotting function for periodic curves model

Description

Plots graph of periodic curves with confidence intervals. Data should be included in the model.

Usage

plot_per_mod(Model, XvarName, Ylab = "Response", Xlab = "Covariate",
  Ylim = NULL, Xlim = NULL, Xmin = NULL, Xmax = NULL, Knots = NULL,
  Title = NULL, Vlines = NULL, Hlines = NULL, Cex.lab = NULL,
  Cex.main = NULL, Cex.axis = NULL, Axes = TRUE, Add = FALSE,
  Col = "black", PlotCI = TRUE, Smooth = FALSE, xLocation = 2)

Arguments

Model The built model
XvarName Name of the x variable in the dataset (column name)
Ylab Label on vertical (y) axis
Xlab Label on horizontal (x) axis
Ylim Limits of y axis
Xlim Limits of x axis
Xmin The min X of data to be predicted (if Smooth)
Xmax The max X of data to be predicted (if Smooth)
Knots Locations of knots of the splines
Title Title of the plot
Vlines Where to plot vertical lines
Hlines Where to plot horizontal lines
Cex.lab Character expansion (aka "size of font") for the labels
Cex.main Character expansion for main text
Cex.axis Character expansion for the axis text
Axes Plot axes
Add Add to existing plot
Col Color of the plotted lines
PlotCI Plot confidence intervals
Smooth Make the Xaxis values equidistant (and the curve smoother)
xLocation If smooth FALSE, the location of the x term in model$x[, xLocation]

Generate design matrix for periodic restricted cubic spline

Description

Generate design matrix for periodic restricted cubic spline.

Usage

rcs_per(x, knots = NULL, nk = 5, xmin = min(x, na.rm = TRUE),
  xmax = max(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
xmin value of the (theoretical) minimum of x
xmax value of the (theoretical) maximum of x #' @examples # 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 ~ rcs_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)

Viral etiology, seasonality and severity of hospitalized patients with severe acute respiratory infections in the Eastern Mediterranean Region, 2007-2014

Description

Data about infections with different viruses across several years.

For more information see Source and References section.

Usage

viral_east_mediteranean

Format

A data frame with variables:

UniqueID

record identification number

Enrolled

Did the patient consent and enroll in the study?: 1=Yes, 0=No

Country

Country of enrollment: Egypt, Jordan, Oman, Qatar, Yemen

EpiYear

Year of enrollment: Integers (2007-2014)

EpiMonth

Month of enrollment: Integers (1-12)

EpiWeek

Week of enrollment: Integers (1-53)

Interval

Number of days between onset of symptoms and hospitalization: Integer

Stay

Number of days between hospitalization and outcome: Integer

Sex

Sex: 1=Female, 0=Male

AgeGrp

Age group: 1=<1 year, 2=1-4 years, 3=5-49 years, 4=50+ years

ChronicDis

Does the patient have any pre-existing chronic disease?: 1=Yes, 0=No

OxTherapy

Did the patient receive oxygen therapy during hospitalization?: 1=Yes, 0=No

Ventilated

Was the patient ventilated during hospitalization?: 1=Yes, 0=No

ICU

Was the patient admitted to an intensive care unit during hospitalization?: 1=Yes, 0=No

Outcome

What was the patient"'"s final hospitalization outcome?: 1=Discharge, 2=Transfer, 3=Death

RSV

Results for respiratory syncytial virus: 1=Positive, 0=Negative

AdV

Results for adenovirus: 1=Positive, 0=Negative

hMPV

Results for human metapneumovirus: 1=Positive, 0=Negative

hPIV1

Results for human parainfluenzavirus type 1: 1=Positive, 0=Negative

hPIV2

Results for human parainfluenzavirus type 2: 1=Positive, 0=Negative

hPIV3

Results for human parainfluenzavirus type 3: 1=Positive, 0=Negative

Flu

Results for influenza: 1=Positive, 0=Negative

Source

http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0180954

References

Horton, Katherine C. AND Dueger, Erica L. AND Kandeel, Amr AND Abdallat, Mohamed AND El-Kholy, Amani AND Al-Awaidy, Salah AND Kohlani, Abdul Hakim AND Amer, Hanaa AND El-Khal, Abel Latif AND Said, Mayar AND House, Brent AND Pimentel, Guillermo AND Talaat, Maha (2017). Viral etiology, seasonality and severity of hospitalized patients with severe acute respiratory infections in the Eastern Mediterranean Region, 2007-2014. PLOS ONE, 12, 1-17.