50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

analogue (version 0.14-0)

residuals.prcurve: Residuals of a principal curve fit.

Description

Returns various representations of the residuals of a principal curve fit.

Usage

## S3 method for class 'prcurve':
residuals(object, which = c("distance", "raw", "smooths", "pca"),
          ...)

Arguments

object
an object of class "prcurve", the result of a call to prcurve.
which
character; the type of residuals to return. See Details.
...
arguments passed to other methods. See Details.

Value

  • A vector of residual distances (which = "distance") or a matrix of residuals (for the other options).

Details

Various types of residual are available for the principal curve. In a departure from the usual convention, which residuals are returned is controlled via the which argument. This is to allow users to pass a type argument to the residuals method for the function used to fit the individual smooth functions when which = "smooths".

The types of residuals available are

[object Object],[object Object],[object Object],[object Object]

For "smooths" residuals, what is returned is governed by the residuals method available for the smooth model fitted to the individual variables. For principal curves fitted using the smoothSpline plugin, see smooth.spline. For principal curves fitted via the smoothGAM plugin, see residuals.gam.

...can be used to pass additional arguments to these residuals methods. In particular, the type argument is commonly used to choose which type of residual is returned by the specific methods.

In the case of principal curves fitted using the plugin smoothSpline, residuals for which = "smooths" are only available if the the additional argument keep.data was specified during fitting via prcurve. See the examples for an illustration of this usage.

See Also

prcurve for fitting a principal curve.

Examples

Run this code
## Load Abernethy Forest data set
  data(abernethy)

  ## Remove the Depth and Age variables
  abernethy2 <- abernethy[, -(37:38)]
  
  ## Fit the principal curve, preserving the data in the smooth.spline
  ## smooth functions fitted via keep.data = TRUE
  aber.pc <- prcurve(abernethy2, method = "ca", keep.data = TRUE)

  ## default "distance" residuals
  resid(aber.pc)

  ## residuals from the underlying smooth models, also illustrates
  ## how to select specific types of residual from the individual
  ## method using argument 'type'
  resid(aber.pc, which = "smooths", type = "deviance")

Run the code above in your browser using DataLab