dr_compare: dr_compare

View source: R/dr-compare.R

dr_compareR Documentation

dr_compare

Description

Compare several dimensionality reduction methods

Usage

dr_compare(
  data,
  funs = list(prcomp = stats::prcomp),
  dim = 1:2,
  metadata = NULL,
  ...
)

Arguments

data

input data. It follows the same contract as dr(): a numeric matrix, a numeric data.frame, or a 'dist' object.

funs

a named list of methods to compare. Each element is either a function, or a list with components fun (the function) and args (an optional list of method-specific arguments). The names are used as the method labels in summary and in the plot, so they must be unique.

dim

the two dimensions to extract, as a numeric vector of length 2. Defaults to 1:2, i.e. the first two dimensions.

metadata

optional sample-level metadata. It is forwarded to fortify() when the long table used by autoplot() is built, so that it becomes available as a column of the plot.

...

additional arguments passed to every method in funs. Arguments supplied through the args element of a method take precedence over ... for that method.

Details

dr_compare() applies several dimensionality reduction (DR) methods to the same input data and collects their results, so that the methods can be compared side by side. Every method is evaluated independently: a method that fails, or that returns fewer dimensions than requested, does not interrupt the others. The outcome of every method is reported in the summary component, which is the main purpose of this function.

A method that fails is never given placeholder coordinates. The failure is recorded in summary$error, and the corresponding element of results is the condition (error) object, so it can be inspected further.

Value

A DrCompare object, a list with the following components:

results

a named list with one element per method. For a method that ran successfully it is a DrResult (see dr()); for a method that failed it is the condition (error) object.

summary

a data.frame with one row per method and the columns method, status, n, k, has_eigenvalue, has_stress and error. status is "ok" if the method ran and returned at least max(dim) dimensions, "insufficient_dims" if it ran but returned too few dimensions, and "failed" if it raised an error. n and k are the number of samples and the number of extracted dimensions, has_eigenvalue and has_stress indicate whether the method produced those quantities, and error holds the error message of a failed method (NA otherwise).

dim, metadata, funs

the corresponding inputs, kept so that autoplot() can rebuild the plot.

Author(s)

Guangchuang Yu

See Also

dr(), available_methods()

Examples

x <- dr_compare(iris[, 1:4], list(pca = stats::prcomp))
x$summary
autoplot(x)

tidydr documentation built on Oct. 9, 2026, 5:07 p.m.