Learn R Programming

imageData (version 0.1-21)

splitSplines: Adds the fits after fitting a natural cubic smoothing spline to subsets of a response to a data.frame

Description

Uses smooth.spline to fit a spline to a subset of the values of response and stores the fitted values in data. The subsets are those values with the same levels combinations of the factors listed in INDICES and the degrees of smoothing is controlled by df. The derivatives of the fitted spline can also be obtained, as can the Relative Growth Rates (RGR).

Usage

splitSplines(data, response, x, INDICES, df = NULL, deriv = NULL, suffices.deriv=NULL, RGR=NULL, na.rm = FALSE, sep=".")

Arguments

data
A data.frame containing the column to be smoothed.
response
A character giving the name of the column in data that is to be smoothed.
x
A character giving the name of the column in data that contains the values of the predictor variable.
INDICES
A character giving the name(s) of the factor(s) that define the subsets of response that are to be smoothed separately. If the columns corresponding to INDICES are not factor(s) then they will be coerced to factor(s). The subsets are formed using split.
df
A numeric specifying the desired equivalent number of degrees of freedom of the smooth (trace of the smoother matrix). Lower values result in more smoothing. If df = NULL, ordinary leave-one-out cross-validation is used to determine the amount of smooth.
deriv
A numeric specifying one or more orders of derivatives that are required.
suffices.deriv
A character giving the characters to be appended to the names of the derivatives.
RGR
A character giving the character to be appended to the name of the RGR. If RGR is not NULL, deriv must include 1 so that the the first derivative is available for caluclating the RGR. If RGR is NULL, the RGR is not calculated.
na.rm
A logical indicating whether or not rows of data with NAs are to be removed prior to smoothing.
sep
A character giving the separator to use when the levels of INDICES are combined. This is needed to avoid using a character that occurs in a factor to delimit levels when the levels of INDICES are combined to identify subsets.

Value

data.frame containing data to which has been added a column with the fitted smooth, the name of the column being response with .smooth apended to it. If deriv is not NULL, columns containing the values of the derivative(s) will be added to data; the name each of these columns will be the value of response with .smooth.dvf appended, where f is the order of the derivative, or the value of response with .smooth. and the corresponding element of suffices.deriv appended. If RGR is not NULL, the RGR is calculated as the ratio of value of the first derivative of the fitted spline and the fitted value for the spline.

See Also

fitSpline, smooth.spline, predict.smooth.spline, splitContGRdiff, split

Examples

Run this code
data(exampleData)
longi.dat <- splitSplines(longi.dat, response="Area", x="xDays", 
                          INDICES = "Snapshot.ID.Tag", 
                          df = 4, deriv=1, suffices.deriv="AGRdv", RGR="RGRdv")

Run the code above in your browser using DataLab