residuals.prcurve {analogue} | R Documentation |

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

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

`object` |
an object of class |

`which` |
character; the type of residuals to return. See Details. |

`...` |
arguments passed to other methods. See 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

`"distance"`

the default residual for a principal curve. This residual is taken as the Euclidean distance between each observations and the point on the principal curve to which it projects, in full multivariate space.

`"raw"`

raw residuals are the basis for

`"distance"`

residuals, and are the difference between the observed and fitted values (position on the curve) for each observation in terms of each variable in the data set. These residuals are in the form of a matrix with number of observation*rows*and number of variables*cols*.`"smooths"`

these residuals are the result of calling

`residuals()`

on each of the smooth models fitted to the individual variables. See below for further details. A matrix of the same dimensions as for`which = "raw"`

is returned.`"pca"`

similar to the raw residuals, but expressed in terms of the principal components of the input data. Hence these residuals are the difference between each observation's location in PCA space and their corresponding location on the curve.

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.

A vector of residual distances (`which = "distance"`

) or a matrix
of residuals (for the other options).

Gavin L. Simpson

`prcurve`

for fitting a principal curve.

```
## 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
res <- resid(aber.pc)
head(res)
## residuals from the underlying smooth models, also illustrates
## how to select specific types of residual from the individual
## method using argument 'type'
res <- resid(aber.pc, which = "smooths", type = "deviance")
dim(res)
head(res[, 1:5]) # just show a few species residuals
```

[Package *analogue* version 0.17-6 Index]