| splitSplines {imageData} | R Documentation | 
Adds the fits after fitting a natural cubic smoothing spline to subsets 
of a response to a data.frame
Description
Uses fitSpline 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).
By default, smooth.spline will issue an error if there are not 
at least four distinct x-values. On the other hand, 
fitSpline issues a warning and sets all smoothed values 
and derivatives to NA. The handling of missing values in the 
observations is controlled via na.x.action and na.y.action.
Usage
splitSplines(data, response, x, INDICES, df = NULL, smoothing.scale = "identity", 
             correctBoundaries = FALSE, 
             deriv = NULL, suffices.deriv=NULL, RGR=NULL, AGR=NULL, sep=".", 
             na.x.action="exclude", na.y.action = "exclude", ...)
Arguments
| data | A data.framecontaining the column to be smoothed. | 
| response | A charactergiving the name of the column indatathat is to be smoothed. | 
| x | A charactergiving the name of the column indatathat contains the values of the predictor variable. | 
| INDICES | A charactergiving the name(s) of thefactor(s) that define the subsets ofresponsethat are to be smoothed separately. If the columns corresponding toINDICESare notfactor(s) then they will be 
coerced tofactor(s). The subsets are formed 
usingsplit. | 
| df | A numericspecifying the desired equivalent number of degrees 
of freedom of the smooth (trace of the smoother matrix). Lower values 
result in more smoothing. Ifdf = NULL, ordinary leave-one-out 
cross-validation is used to determine the amount of smooth. | 
| smoothing.scale | A charactergiving the scale on which smoothing 
is to be performed. The two possibilites are"identity", for directly 
smoothing the observedresponse, and"logarithmic", for scaling thelog-transformedresponse. | 
| correctBoundaries | A logicalindicating whether the fitted 
spline values are to have the method of Huang (2001) applied 
to them to correct for estimation bias at the end-points. Note thatderivmust beNULLforcorrectBoundariesto be 
set toTRUE. | 
| deriv | A numericspecifying one or more orders of derivatives 
that are required. | 
| suffices.deriv | A charactergiving the characters to be 
appended to the names of the derivatives. | 
| RGR | A charactergiving the character to be appended 
to the smoothedresponseto create the RGR name, 
but only whensmoothing.scaleisidentity. 
Whensmoothing.scaleisidentity: 
(i) ifRGRis notNULLderivmust include 1 so that the first derivative is 
available for calculating the RGR; (ii) ifRGRisNULL, 
the RGR is not calculated from the AGR. 
Whensmoothing.scaleislogarithmic, 
the RGR is the backtransformed first derivative and so, to obtain it, merely 
include1inderivand any suffix for it insuffices.deriv. | 
| AGR | A charactergiving the character to be appended 
to the smoothedresponseto create the AGR name, 
but only whensmoothing.scaleislogarithmic. 
Whensmoothing.scaleislogarithmic: (i) 
ifAGRis notNULL,derivmust include 1 so that the first derivative is 
available for calculating the AGR; (ii) IfAGRisNULL, 
the AGR is not calculated from the RGR. Whensmoothing.scaleisidentity, 
the AGR is the first derivative and so, to obtain it, merely 
include1inderivand any suffix for it insuffices.deriv. | 
| sep | A charactergiving the separator to use when the 
levels ofINDICESare combined. This is needed to avoid 
using acharacterthat occurs in a factor to delimit 
levels when the levels ofINDICESare combined to identify 
subsets. | 
| na.x.action | A characterstring that specifies the action to 
be taken when values ofxareNA. The possible 
values arefail,excludeoromit. 
Forexcludeandomit, predictions and derivatives 
will only be obtained for nonmissing values ofx. 
The difference between these two codes is that forexcludethe returneddata.framewill have as many rows asdata, the 
missing values have been incorporated. | 
| na.y.action | A characterstring that specifies the action to 
be taken when values ofy, or theresponse, areNA.  The possible values arefail,exclude,omit,allx,trimx,ltrimxorrtrimx. For  all options, exceptfail, missing 
values inywill be removed before smoothing. 
Forexcludeandomit, predictions 
and derivatives will be obtained only for nonmissing values ofxthat do not have missingyvalues. Again, the 
difference between these two is that, only forexcludewill the missing values be incorporated into the 
returneddata.frame. Forallx, predictions and 
derivatives will be obtained for all nonmissingx. 
Fortrimx, they will be obtained for all nonmissingxbetween the first and last nonmissingyvalues 
that have been ordered forx; forltrimxandutrimxeither the lower or upper missingyvalues, respectively, are trimmed. | 
| ... | allows for arguments to be passed to smooth.spline. | 
Value
A data.frame containing  data to which has been 
added a column with the fitted smooth, the name of the column being 
response with .smooth appended 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. 
Any pre-existing smoothed and derivative columns in data will be 
replaced. The ordering of the data.frame for the x 
values will be preserved as far as is possible; the main difficulty 
is with the handling of missing values by the function merge. 
Thus, if missing values in x are retained, they will occur at 
the bottom of each subset of INDICES and the order will be 
problematic when there are missing values in y and 
na.y.action is set to omit.
Author(s)
Chris Brien
References
Huang, C. (2001). Boundary corrected cubic smoothing splines. Journal of Statistical Computation and Simulation, 70, 107-121.
See Also
fitSpline, smooth.spline, 
predict.smooth.spline, splitContGRdiff, split
Examples
data(exampleData)
longi.dat <- splitSplines(longi.dat, response="Area", x="xDays", 
                          INDICES = "Snapshot.ID.Tag", 
                          df = 4, deriv=1, suffices.deriv="AGRdv", RGR="RGRdv")
[Package 
imageData version 0.1-62 
Index]