| genpca | R Documentation |
Compute a PCA in a inner-product space defined by row and coulmn constraint matrices.
genpca( X, A = NULL, M = NULL, ncomp = min(dim(X)), preproc = center(), deflation = FALSE, svd_init = TRUE, threshold = 1e-06, use_cpp = TRUE )
A |
the column constraints. Can be a |
M |
the row constraints. Can be a |
Abdi, H. (2007). Singular value decomposition (SVD) and generalized singular value decomposition. Encyclopedia of measurement and statistics, 907-912.
Allen, G. I., Grosenick, L., & Taylor, J. (2014). A generalized least-square matrix decomposition. Journal of the American Statistical Association, 109(505), 145-159.
N <- 10
coords <- expand.grid(x=seq(1,N), y=seq(1,N))
img <- apply(coords, 1, function(x) {
x1 <- 1 - pnorm(abs(x[1] - N/2), sd=8)
x2 <- 1 - pnorm(abs(x[2] - N/2), sd=8)
x1*x2
})
mat <- matrix(img, N,N)
mlist <- replicate(10, as.vector(mat + rnorm(length(mat))*.02), simplify=FALSE)
X <- do.call(rbind, mlist)
## spatial smoother
S <- neighborweights:::spatial_smoother(coords, sigma=3, nnk=4)
S <- cov(as.matrix(S))
S <- S/eigen(S)$values[1]
T <- neighborweights:::spatial_smoother(as.matrix(1:10), sigma=3, nnk=3)
T <- cov(as.matrix(T))
T <- T/(eigen(T)$values[1])
gp1 <- genpca(X, A=S, ncomp=9)
gp1a <- genpca(X, A=S, M=T, ncomp=9)
Xs <- do.call(rbind, lapply(1:nrow(X), function(i) X[i,,drop=FALSE] %*% S))
gp2 <- genpca(as.matrix(Xs), ncomp=2)
## use an adjacency matrix to weight items sharing an index.
X <- matrix(rnorm(50*100), 50, 100)
colind <- rep(1:10, 10)
S <- neighborweights:::spatial_adjacency(as.matrix(colind), dthresh=4, sigma=1, nnk=27, normalized=TRUE, include_diagonal=TRUE, weight_mode="heat")
diag(S) <- 1
S <- S/RSpectra::svds(S,k=1)$d
gp1 <- genpca(X, A=S, ncomp=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.