gsvd: Generalized singular value decomposition

Description Usage Arguments Value Author(s) See Also Examples

View source: R/gsvd.R

Description

gsvd takes in left (LW) and right (RW) constraints (usually diagonal matrices, but any positive semi-definite matrix is fine) that are applied to the data (X). Left and right constraints are used for the orthogonality conditions.

Usage

1
gsvd(X, LW, RW, k = 0, tol = .Machine$double.eps)

Arguments

X

a data matrix to decompose

LW

Left Weights – the constraints applied to the left side (rows) of the matrix and thus left singular vectors.

RW

Right Weights – the constraints applied to the right side (columns) of the matrix and thus right singular vectors.

k

total number of components to return though the full variance will still be returned (see d_full). If 0, the full set of components are returned.

tol

default is .Machine$double.eps. A tolerance level for eliminating effectively zero (small variance), negative, imaginary eigen/singular value components.

Value

A list with eleven elements:

d_full

A vector containing the singular values of X above the tolerance threshold (based on eigenvalues).

l_full

A vector containing the eigen values of X above the tolerance threshold (tol).

d

A vector of length min(length(d_full), k) containing the retained singular values of X

l

A vector of length min(length(l_full), k) containing the retained eigen values of X

u

Left (rows) singular vectors. Dimensions are nrow(X) by k.

p

Left (rows) generalized singular vectors. Dimensions are nrow(X) by k.

fi

Left (rows) component scores. Dimensions are nrow(X) by k.

v

Right (columns) singular vectors. Dimensions are ncol(X) by k.

q

Right (columns) generalized singular vectors. Dimensions are ncol(X) by k.

fj

Right (columns) component scores. Dimensions are ncol(X) by k.

Author(s)

Derek Beaton

See Also

tolerance_svd, geigen and gplssvd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 data(wine, package="GSVD")
 wine.objective <- wine$objective
 ## Principal components analysis: "covariance"
 ## "covariance" PCA
 cov.pca.data <- scale(wine.objective,scale=FALSE)
 cov.pca.res <- gsvd(cov.pca.data)

 ## Principal components analysis: "correlation"
 cor.pca.data <- scale(wine.objective,scale=TRUE)
 cor.pca.res <- gsvd(cor.pca.data)

 ## Principal components analysis: "correlation" with the covariance matrix and constraints
 cor.pca.res2 <- gsvd(cov.pca.data,RW=1/apply(wine.objective,2,var))


 ## Correspondence analysis
 data(authors, package="GSVD")
 Observed <- authors/sum(authors)
 row.w <- rowSums(Observed)
 col.w <- colSums(Observed)
 Expected <- row.w %o% col.w
 Deviations <- Observed - Expected
 ca.res <- gsvd(Deviations,1/row.w,1/col.w)


 ## Multiple correspondence analysis
 data("snps.druguse", package="GSVD")
 X <- model.matrix(~ .,
     data=snps.druguse$DATA1,
     contrasts.arg = lapply(snps.druguse$DATA1, contrasts, contrasts=FALSE))[,-1]
 Observed <- X/sum(X)
 row.w <- rowSums(Observed)
 col.w <- colSums(Observed)
 Expected <- row.w %o% col.w
 Deviations <- Observed - Expected
 ca.res <- gsvd(Deviations,1/row.w,1/col.w)

derekbeaton/GSVD documentation built on Jan. 2, 2021, 9:21 p.m.