splitSplines | R Documentation |
data.frame
in long formatUses 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 factor
s listed in individuals
. 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 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 splitContGRdiff
.
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.
Note: this function is soft deprecated and may be removed in
future versions.
Use byIndv4Times_SplinesGRs
.
splitSplines(data, response, response.smoothed = NULL, x,
individuals = "Snapshot.ID.Tag", INDICES = NULL,
smoothing.method = "direct", smoothing.segments = NULL,
spline.type = "NCSS", df=NULL, lambda = NULL,
npspline.segments = NULL,
correctBoundaries = FALSE,
deriv = NULL, suffices.deriv = NULL, extra.rate = NULL,
sep = ".",
na.x.action="exclude", na.y.action = "exclude", ...)
data |
A |
response |
A |
response.smoothed |
A |
x |
A |
individuals |
A |
INDICES |
A pseudonym for |
smoothing.method |
A |
smoothing.segments |
A named |
spline.type |
A |
df |
A |
lambda |
A |
npspline.segments |
A |
correctBoundaries |
A |
deriv |
A |
suffices.deriv |
A |
extra.rate |
A named |
sep |
A |
na.x.action |
A |
na.y.action |
A |
... |
allows for arguments to be passed to |
A data.frame
containing data
to which has been
added a column with the fitted smooth, the name of the column being
response.smoothed
. 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.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.
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 individuals
and the order will be
problematic when there are missing values in y
and
na.y.action
is set to omit
.
Chris Brien
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.
fitSpline
, probeSmoothing
, splitContGRdiff
,
smooth.spline
, predict.smooth.spline
,
split
data(exampleData)
#smoothing with growth rates calculated using derivates
longi.dat <- splitSplines(longi.dat, response="PSA", x="xDAP",
individuals = "Snapshot.ID.Tag",
df = 4, deriv=1, suffices.deriv="AGRdv",
extra.rate = c(RGRdv = "RGR"))
#Use P-splines
longi.dat <- splitSplines(longi.dat, response="PSA", x="xDAP",
individuals = "Snapshot.ID.Tag",
spline.type = "PS", lambda = 0.1, npspline.segments = 10,
deriv=1, suffices.deriv="AGRdv",
extra.rate = c(RGRdv = "RGR"))
#with segmented smoothing
longi.dat <- splitSplines(longi.dat, response="PSA", x="xDAP",
individuals = "Snapshot.ID.Tag",
smoothing.segments = list(c(28,34), c(35,42)), df = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.