Skip to content

Commit

Permalink
Fix for Issue #250
Browse files Browse the repository at this point in the history
fix: when ILR/CLR was used, X was of invalid class. Added check to ensure `svds()` can operate on X
  • Loading branch information
Max-Bladen committed Oct 6, 2022
1 parent 81399a0 commit 62c7f10
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pca <- function(X,
sdev <- res$eig
loadings <- res$p
} else {

X <- matrix(X, ncol=ncol(X), nrow=nrow(X))
if (logratio %in% c('CLR', 'none')) {
#-- if data is complete use singular value decomposition
#-- borrowed from 'prcomp' function
Expand All @@ -261,7 +261,7 @@ pca <- function(X,
} else {
# if 'ILR', transform data and then back transform in clr space (from RobCompositions package)
# data have been transformed above
res = svds(X, k = ncomp, nu = max(1, nrow(X) - 1))
res = svds(X, k = ncomp, nu = max(1, ncomp))
sdev = res$d[1:ncomp] / sqrt(max(1, nrow(X) - 1)) # Note: what differs with RobCompo is that they use: cumsum(eigen(cov(X))$values)/sum(eigen(cov(X))$values)
# calculate loadings using back transformation to clr-space
loadings = V %*% res$v[, 1:ncomp, drop = FALSE]
Expand Down

0 comments on commit 62c7f10

Please sign in to comment.