Skip to content

Commit

Permalink
Added $x and $rotation to pca() output (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-Bladen authored Dec 8, 2022
1 parent 3f550a8 commit 6530fdc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ pca <- function(X,
sdev <- res$eig
loadings <- res$p
} else {

if (logratio %in% c('CLR', 'none')) {
#-- if data is complete use singular value decomposition
#-- borrowed from 'prcomp' function
Expand Down Expand Up @@ -283,7 +282,8 @@ pca <- function(X,
result <- c(result, .get_var_stats(X = result$X, sdev = result$sdev))
expected_output_names <- c("call", "X", "ncomp", "center", "scale", "names",
"sdev", "loadings", "variates", "prop_expl_var", "var.tot",
"cum.var")
"cum.var", "rotation", "x")

if (names(result) %!=% expected_output_names)
{
stop("Unexpected error. Please submit an issue at\n",
Expand Down Expand Up @@ -318,6 +318,7 @@ pca <- function(X,
sdev,
loadings,
variates = NULL) {

ncomp <- result$ncomp
pc_names <- paste("PC", seq_len(ncomp), sep = "")

Expand All @@ -333,7 +334,12 @@ pca <- function(X,
dimnames(loadings) = list(colnames(X), pc_names)
dimnames(variates) = list(rownames(X), pc_names)

result[c('sdev', 'loadings', 'variates')] <- list(sdev, list(X=loadings), list(X=variates))
result[c('sdev', 'loadings', 'variates', 'x', 'rotation')] <- list(sdev,
list(X=loadings),
list(X=variates),
variates,
loadings)

result
}

Expand Down

0 comments on commit 6530fdc

Please sign in to comment.