Perform affine coordinate transformations.
coords(p, name = NULL, shift = 0)
appendTrfm(trfm, op = c("diag", "orth"), val)
toCoords(trfm, x)
fromCoords(trfm, y, apply.shift = TRUE)The number of variables in the original data.
A short name for the coordinate transformation (optional).
A value subtracted from the data as the first step of the coordinate transformation. Usually, this will be the mean of the data (optional).
An object of class coords.
The type of transformation to append.
Data for the transformation to append.
Data matrix, rows are observations, columns are variables.
Transformed data matrix, rows are observations, columns are variables.
Whether to apply the final shift of coordinates.
Set this to FALSE in order to only apply the linear part of the
transformation.
An object of class coords, as a list with the following
components:
the number of variables in the original data set
the number of variables in the transformed data set
the affine part of the transformation
the name of the transformation
a representation of the transformation (internal use only)
The function coords() creates a new object representing an
affine coordinate transformation. Initially, the object represents a
shift by the amount shift, mapping p-dimensional vectors
x to x-shift. The function appendTrfm() can then
be used to modify the transformation. The optional argument
name, if set, is used when printing objects of class
coords.
The function toCoords() applies the affine transformation trfm
to the data x. The data x must either be a vector of
length trfm$p, in which case the result is a vector of
length trfm$q, or a matrix with trfm$p columns, in which case
the transformation is applied to each row of the matrix separately.
The function fromCoords() implements the inverse transform
to toCoords(). The output always satisfies
toCoords(trfm, fromCoords(trfm, y)) == y. If
trfm$p == trfm$q, i.e. if the transformation is bijective,
the fromCoords(trfm, toCoords(trfm, x)) == x also holds.
The argument apply.shift can be set to false to apply only
the linear part of the (inverse) transformation, leaving out the
final shift.
The function appendTrfm() concatenates trfm with an
additional, linear transformation and returns the result. The
arguments op and val specify which kind of linear
transformation to append. There are two choices for op:
diag denotes multiplication with a diagonal matrix: an input
vector x is mapped to the output x * val. The scaling factor
val can either be a vector of length trfm$q (for element-wise
scaling), or a number.
orth denotes multiplication with an orthogonal matrix.
val must be a matrix with orthogonal columns (not necessarily
square) and trfm$q rows. An input vector x is mapped
to the output x %*% orth.
The new transformation is applied after any other transformations
already associated with trfm.
# NOT RUN {
pc <- PCA(iris[, 1:4], n.comp = 3)
toCoords(pc, c(5, 3, 4, 1))
fromCoords(pc, c(1, 0, 0))
# }
Run the code above in your browser using DataLab