Learn R Programming

imageData (version 0.1-21)

fitSpline: Produce the fits from a natural cubic smoothing spline applied to a response in a data.frame

Description

Uses smooth.spline to fit a spline to all the values of response stored in data. The amount of smoothing is controlled by df. The derivatives of the fitted spline can also be obtained, as can the Relative Growth Rate (RGR).

Usage

fitSpline(data, response, x, df=NULL, deriv=NULL, suffices.deriv=NULL, RGR=NULL, na.rm=FALSE)

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.
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.

Value

data.frame containing x and the fitted smooth. The names of the columns will be the value of x and the value of response with .smooth appended. If deriv is not NULL, columns containing the values of the derivative(s) will be added to the data.frame; the name each of 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

splitSplines, smooth.spline, predict.smooth.spline, splitContGRdiff

Examples

Run this code
data(exampleData)
fit <- fitSpline(longi.dat, response="Area", , x="xDays", df = 4,
                 deriv=c(1,2), suffices.deriv=c("AGRdv","Acc"))

Run the code above in your browser using DataLab