| fitSpline {growthPheno} | R Documentation |
Fits a spline to a response in a data.frame, and growth rates can be
computed using derivatives
Description
Uses smooth.spline to fit a natural cubic smoothing spline or JOPS to fit a
P-spline to all the values of response stored in data.
The amount of smoothing can be controlled by tuning parameters, these being
related to the penalty. For a natural cubic smoothing spline, these are
df or lambda and, for a P-spline, it is lambda.
For a P-spline, npspline.segments also influences the smoothness of the fit.
The smoothing.method provides for direct and logarithmic
smoothing. The method of Huang (2001) for correcting the fitted spline for
estimation bias at the end-points will be applied when fitting using a
natural cubic smoothing spline if correctBoundaries is TRUE.
The derivatives of the fitted spline can also be obtained, and the
Absolute and Relative Growth Rates ( AGR and RGR) computed using them, provided
correctBoundaries is FALSE. Otherwise, growth rates can be
obtained by difference using byIndv4Times_GRsDiff.
The handling of missing values in the observations is controlled via
na.x.action and na.y.action. If there are not
at least four distinct, nonmissing x-values, a warning is issued and
all smoothed values and derivatives are set to NA.
The function probeSmoothing can be used to investgate the effect
the smoothing parameters (smoothing.method and df or
lambda) on the smooth that results.
Usage
fitSpline(data, response, response.smoothed, x,
smoothing.method = "direct",
spline.type = "NCSS", df = NULL, lambda = NULL,
npspline.segments = NULL, correctBoundaries = FALSE,
deriv = NULL, suffices.deriv = NULL, extra.rate = NULL,
na.x.action = "exclude", na.y.action = "trimx", ...)
Arguments
data |
A |
response |
A |
response.smoothed |
A |
x |
A |
smoothing.method |
A |
spline.type |
A |
df |
A |
lambda |
A |
npspline.segments |
A |
correctBoundaries |
A |
deriv |
A |
suffices.deriv |
A |
.
extra.rate |
A named |
na.x.action |
A |
na.y.action |
A |
... |
allows for arguments to be passed to |
Value
A list with two components named predictions and
fit.spline.
The predictions component is a data.frame containing x
and the fitted smooth. The names of the columns will be the value of
x and the value of response.smoothed. The number of rows in
the data.frame will be equal to the number of pairs that have neither
a missing x or response and the order of x will be the
same as the order in data. If deriv is not NULL,
columns containing the values of the derivative(s) will be added to the
data.frame; the name each of these columns will be the value of
response.smoothed with .dvf appended, where f is the
order of the derivative, or the value of response.smoothed 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.
The fit.spline component is a list with components
x:the distinct x values in increasing order;
y:the fitted values, with boundary values possibly corrected, and corresponding to
x;lev:leverages, the diagonal values of the smoother matrix (NCSS only);
lambda:the value of lambda (corresponding to
sparfor NCSS - seesmooth.spline);df:the efective degrees of freedom;
npspline.segments:the number of equally spaced segments used for smoothing method set to
PS;uncorrected.fit:the object returned by
smooth.splineforsmoothing methodset toNCSSor byJOPS::psNormalforPS.
Author(s)
Chris Brien
References
Eilers, P.H.C and Marx, B.D. (2021) Practical smoothing: the joys of P-splines. Cambridge University Press, Cambridge.
Huang, C. (2001) Boundary corrected cubic smoothing splines. Journal of Statistical Computation and Simulation, 70, 107-121.
See Also
splitSplines, probeSmoothing,
byIndv4Times_GRsDiff, smooth.spline,
predict.smooth.spline, JOPS.
Examples
data(exampleData)
fit <- fitSpline(longi.dat, response="PSA", response.smoothed = "sPSA",
x="xDAP", df = 4,
deriv=c(1,2), suffices.deriv=c("AGRdv","Acc"))
fit <- fitSpline(longi.dat, response="PSA", response.smoothed = "sPSA",
x="xDAP",
spline.type = "PS", lambda = 0.1, npspline.segments = 10,
deriv=c(1,2), suffices.deriv=c("AGRdv","Acc"))
fit <- fitSpline(longi.dat, response="PSA", response.smoothed = "sPSA",
x="xDAP", df = 4,
deriv=c(1), suffices.deriv=c("AGRdv"),
extra.rate = c(RGR.dv = "RGR"))