tidybulk icon indicating copy to clipboard operation
tidybulk copied to clipboard

"Proportion of variance explained" values on reduce_dimensions() output

Open canholyavkin opened this issue 2 years ago • 1 comments

The base prcomp() function provides the Proportion of variance explained values after the PCA analysis.

pca <- prcomp(USArrests, scale = TRUE)
summary(pca)
#Importance of components:
#                          PC1    PC2     PC3     PC4
#Standard deviation     1.5749 0.9949 0.59713 0.41645
#Proportion of Variance 0.6201 0.2474 0.08914 0.04336
#Cumulative Proportion  0.6201 0.8675 0.95664 1.00000

As you know, those values are pretty important in evaluating the variability in eigenvectors. However, I couldn't find those values on the reduce_dimensions() output. Is it possible to obtain those values with tidybulk?

canholyavkin avatar Jul 25 '22 06:07 canholyavkin

Yes the message on how to get them wasn't showing.

Now

se = se |> reduce_dimensions(method="PCA")
No group or design set. Assuming all samples belong to one group.
Getting the 23 most variable genes
Fraction of variance explained by the selected principal components
# A tibble: 2 × 2
  `Fraction of variance`    PC
                   <dbl> <int>
1                  0.599     1
2                  0.188     2
tidybulk says: to access the raw results do `attr(..., "internals")$PCA`

And recover the pca object as such

attr(se, "internals")$PCA

Pull request below, please check branch to see if has solved your problem.

stemangiola avatar Jul 26 '22 01:07 stemangiola