byIndv4Times_SplinesGRs {growthPheno} | R Documentation |
For a response in a data.frame
in long format, computes,
for a single set of smoothing parameters, smooths of the
response, possibly along with growth rates calculated from the
smooths.
Description
Uses smoothSpline
to fit a spline to the values
of response
for each individual
and stores the fitted
values in data
. The degree of smoothing is controlled by the
tuning parameters df
and lambda
, related to the
penalty, and by npspline.segments
. The smoothing.method
provides for direct
and logarithmic
smoothing.
The Absolute and Relative Growth Rates ( AGR and RGR) can be computed
either using the first derivatives of the splines or by differencing
the smooths. If using the first derivative to obtain growth rates,
correctBoundaries
must be FALSE
. Derivatives other than the
first derivative can also be produced. The function
byIndv4Times_GRsDiff
is used to obtain growth rates by
differencing.
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
, df
or
lambda
) on the smooth that results.
Usage
byIndv4Times_SplinesGRs(data, response, response.smoothed = NULL,
individuals = "Snapshot.ID.Tag", times,
smoothing.method = "direct", smoothing.segments = NULL,
spline.type = "NCSS", df=NULL, lambda = NULL,
npspline.segments = NULL,
correctBoundaries = FALSE,
rates.method = "differences",
which.rates = c("AGR","RGR"),
suffices.rates = NULL, sep.rates = ".",
avail.times.diffs = FALSE, ntimes2span = 2,
extra.derivs = NULL, suffices.extra.derivs=NULL,
sep.levels = ".",
na.x.action="exclude", na.y.action = "trimx", ...)
Arguments
data |
A |
response |
A |
response.smoothed |
A |
individuals |
A |
times |
A |
smoothing.method |
A |
smoothing.segments |
A named |
spline.type |
A |
df |
A |
lambda |
A |
npspline.segments |
A |
correctBoundaries |
A |
rates.method |
A |
which.rates |
A |
suffices.rates |
A |
sep.rates |
A |
avail.times.diffs |
A |
ntimes2span |
A |
extra.derivs |
A |
suffices.extra.derivs |
A |
.
sep.levels |
A |
na.x.action |
A |
na.y.action |
A |
... |
allows for arguments to be passed to |
Value
A data.frame
containing data
to which has been
added a column with the fitted smooth, the name of the column being
the value of response.smoothed
. If rates.method
is
not none
, columns for the growth rates listed in
which.rates
will be added to data
; the names each of
these columns will be the value of response.smoothed
with
the elements of which.rates
appended.
When rates.method
is derivatives
and
smoothing.method
is direct
, the AGR
is obtained
from the first derivative of the spline for each value of times
and the RGR
is calculated as the AGR
divided by the
value of the response.smoothed
for the corresponding time.
When rates.method
is derivatives
and
smoothing.method
is logarithmic
, the RGR
is
obtained from the first derivative of the spline and the AGR
is calculated as the RGR
multiplied by the corresponding
value of the response.smoothed
.
If extra.derivs
is not NULL
, the values for the
nominated derivatives will also be added to data
; the names
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
with the corresponding element of suffices.deriv
appended.
Any pre-existing smoothed and growth rate columns in data
will be
replaced. The ordering of the data.frame
for the times
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 times
are retained, they will occur at
the bottom of each subset of individuals
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
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
smoothSpline
, probeSmoothing
, byIndv4Times_GRsDiff
,
smooth.spline
, predict.smooth.spline
,
split
Examples
data(exampleData)
#smoothing with growth rates calculated using derivates
longi.dat <- byIndv4Times_SplinesGRs(data = longi.dat,
response="PSA", response.smoothed = "sPSA",
times="DAP",
df = 4, rates.method = "deriv",
suffices.rates = c("AGRdv", "RGRdv"))
#Use P-splines
longi.dat <- byIndv4Times_SplinesGRs(data = longi.dat,
response="PSA", response.smoothed = "sPSA",
individuals = "Snapshot.ID.Tag", times="DAP",
spline.type = "PS", lambda = 0.1,
npspline.segments = 10,
rates.method = "deriv",
suffices.rates = c("AGRdv", "RGRdv"))
#with segmented smoothing and no growth rates
longi.dat <- byIndv4Times_SplinesGRs(data = longi.dat,
response="PSA", response.smoothed = "sPSA",
individuals = "Snapshot.ID.Tag", times="DAP",
smoothing.segments = list(c(28,34), c(35,42)),
df = 5, rates.method = "none")