Learn R Programming

netCoin (version 2.1.49)

layoutsAlign: Planes of a scattergram laid over one another

Description

layoutsAlign brings the planes of a netCoin object from surScat to a common footing, as layoutsDist does to measure how far apart they are, and hands back the transformed coordinates themselves.

Usage

layoutsAlign(x, align=c("procrustes", "cloud", "canvas", "none"), to=1, gpa=FALSE,
             weights=NULL, which=NULL, suffix=NULL, tol=1e-10, maxit=100,
             who="layoutsAlign")

Value

When x is a 'netCoin' object, the same object with the aligned planes in place of the original ones in its $layouts (or each one next to its original, when suffix is given), the first plane also as its fx/fy columns, and the cluster centroids in $clusters computed again on the new coordinates. The details of the alignment go in its attribute "alignment".

When x is a list of planes, a named list holding the aligned ones, with those details as attributes of the list.

The details are: the method (align), the reference plane (to), whether gpa was used, the rows the fit was estimated on (rows) and those left out (dropped), the center, scale and rotation matrix applied to every plane, and, with align="procrustes" and two columns, the angle of each rotation in degrees and whether it involved a reflection. With gpa=TRUE there are also the consensus plane (the mean of all the aligned ones), the number of iterations and whether the fit converged.

Arguments

x

a 'netCoin' object from surScat, or a list of planes, each a matrix or data.frame of two columns of coordinates holding one row per node.

align

how the planes are put on an equal footing: "procrustes" (default) centres them, brings them to the same size and rotates (or reflects) each one onto the reference; "cloud" does the same without rotating; "canvas" stretches every axis to the same range, as the viewer does; "none" leaves them as they are. See layoutDist.

to

the reference plane, as its name or its index among all the planes of x. The first one by default, which in a scattergram from surScat is the plane it was drawn with (for instance "PCA" or "MCA"). The names are those printed under "Planes" by print(x), or names(x$layouts): a reduction taken from a 'looking4clusters' object by addAxes keeps its own name, such as "pca" or "tsne", unless name was given there.

gpa

with align="procrustes", rotate every plane towards the mean of them all (generalized Procrustes analysis) instead of towards to. The reference then only sets the orientation and the units in which the whole set is handed back.

weights

what every node counts for in the fit, as in layoutsDist.

which

the planes to align, as names or as indices. NULL (default) takes every one of them. The reference need not be among them; planes left out are kept as they were.

suffix

only for a 'netCoin' object. NULL (default) replaces its planes by the aligned ones. A string keeps the original planes and places each aligned one right after its original, so that the selector of the viewer offers them side by side, named as the original followed by suffix (with suffix="'", "sepal" gives "sepal'"). The titles of its axes take the suffix too ("PC1" gives "PC1'"), as a rotated axis is no longer the original one. The reference plane is not added again, as it is left unchanged, except with gpa=TRUE. Whether or not a suffix is given, an axis titled with the percentage of variance of its factor, as in "PC1 (73.0%)", is titled with the percentage the rotated axis holds instead ("PC1' (71.4%)"): the factors being uncorrelated, it is worked out from theirs and the rotation, and the two axes of the plane keep the same total.

tol, maxit

convergence tolerance and maximum number of iterations of the generalized Procrustes fit.

who

the name errors and messages are issued under.

Author

Modesto Escobar, Department of Sociology and Communication, University of Salamanca.

Details

The fit is estimated on the rows that are complete in every plane involved, the same ones for all of them, and then applied to every row of each plane: a node missing from one plane keeps its place in the others.

The result is expressed in the units of the reference plane, which is therefore left just as it was (except under gpa=TRUE, where every plane moves towards the consensus). A plane compared with it under align="procrustes" is thus turned to be read on the same axes, and the distance layoutsDist reports between them is the mean distance between the two sets of coordinates divided by the scale of the reference.

Under gpa=TRUE no plane is favoured over the others. The mean has no orientation of its own, so the whole set is finally turned, as one, to lie as close as possible to the reference.

See Also

layoutsDist, layoutDist, addAxes, surScat

Examples

Run this code
if (FALSE) {
data(iris)
S <- surScat(iris, variables=names(iris)[1:4], type="pca", nclusters=3)
P <- prcomp(iris[,1:4], scale.=TRUE)$x
S <- addAxes(S, P[,3:4])
S <- addAxes(S, as.matrix(iris[,1:2]), name="sepal")

# every plane turned onto PCA, the one drawn first
A <- layoutsAlign(S)
A
attr(A, "alignment")$angle

# onto another plane, by its name
A <- layoutsAlign(S, to="sepal")

# the original planes kept, the aligned ones added as "PC3-PC4'" and "sepal'"
A <- layoutsAlign(S, suffix="'")
names(A$layouts)

# towards the mean of them all
G <- layoutsAlign(S, gpa=TRUE)
head(attr(G, "alignment")$consensus)

# the coordinates alone, from a list of planes
L <- layoutsAlign(S$layouts, which=c("sepal", "PC3-PC4"), to=1)
}

Run the code above in your browser using DataLab