prcurve {analogue} | R Documentation |
Fits a principal curve to m-dimensional data
Description
A principal curve is a non-parametric generalisation of the principal component and is a curve that passes through the middle of a cloud of data points for a certain definition of ‘middle’.
Usage
prcurve(X, method = c("ca", "pca", "random", "user"), start = NULL,
smoother = smoothSpline, complexity, vary = FALSE,
maxComp, finalCV = FALSE, axis = 1, rank = FALSE,
stretch = 2, maxit = 10, trace = FALSE, thresh = 0.001,
plotit = FALSE, ...)
initCurve(X, method = c("ca", "pca", "random", "user"), rank = FALSE,
axis = 1, start)
Arguments
X |
a matrix-like object containing the variables to which the principal curve is to be fitted. |
method |
character; method to use when initialising the principal
curve. |
start |
numeric vector specifying the initial curve when
|
smoother |
function; the choice of smoother used to fit the
principal curve. Currently, the only options are
|
complexity |
numeric; the complexity of the fitted smooth functions. The function passed as argument |
vary |
logical; should the complexity of the smoother fitted to
each variable in |
maxComp |
numeric; the upper limt on the allowed complexity. |
finalCV |
logial; should a final fit of the smooth function be performed using cross validation? |
axis |
numeric; the ordinaion axis to use as the initial curve. |
rank |
logical; should rank position on the gradient be used? Not yet implemented. |
stretch |
numeric; a factor by which the curve can be extrapolated when points are projected. Default is 2 (times the last segment length). |
maxit |
numeric; the maximum number of iterations. |
trace |
logical; print progress on the iterations be printed to the console? |
thresh |
numeric; convergence threshold on shortest distances to
the curve. The algorithm is considered to have converged when the
latest iteration produces a total residual distance to the curve
that is within |
plotit |
logical; should the fitting process be plotted? If
|
... |
additional arguments are passed solely on to the function
|
Value
An object of class "prcurve"
with the following components:
s |
a matrix corresponding to |
tag |
an index, such that |
lambda |
for each point, its arc-length from the beginning of the curve. |
dist |
the sum-of-squared distances from the points to their projections. |
converged |
logical; did the algorithm converge? |
iter |
numeric; the number of iterations performed. |
totalDist |
numeric; total sum-of-squared distances. |
complexity |
numeric vector; the complexity of the smoother
fitted to each variable in |
call |
the matched call. |
ordination |
an object of class |
data |
a copy of the data used to fit the principal curve. |
Note
The fitting function uses function
project_to_curve
in package princurve
to find the projection of the data on to the fitted curve.
Author(s)
Gavin L. Simpson
See Also
smoothGAM
and smoothSpline
for the
wrappers fitting smooth functions to each variable.
Examples
## Load Abernethy Forest data set
data(abernethy)
## Remove the Depth and Age variables
abernethy2 <- abernethy[, -(37:38)]
## Fit the principal curve using the median complexity over
## all species
aber.pc <- prcurve(abernethy2, method = "ca", trace = TRUE,
vary = FALSE, penalty = 1.4)
## Extract fitted values
fit <- fitted(aber.pc) ## locations on curve
abun <- fitted(aber.pc, type = "smooths") ## fitted response
## Fit the principal curve using varying complexity of smoothers
## for each species
aber.pc2 <- prcurve(abernethy2, method = "ca", trace = TRUE,
vary = TRUE, penalty = 1.4)
## Predict new locations
take <- abernethy2[1:10, ]
pred <- predict(aber.pc2, take)
## Not run:
## Fit principal curve using a GAM - currently slow ~10secs
aber.pc3 <- prcurve(abernethy2 / 100, method = "ca", trace = TRUE,
vary = TRUE, smoother = smoothGAM, bs = "cr", family = mgcv::betar())
## End(Not run)