问题描述
我想获取singular values of a matrix in R
以获得主要成分,然后也将princomp(x)也用于比较结果
I want to get singular values of a matrix in R
to get the principal components, then make princomp(x) too to compare results
我知道princomp()会给出主要成分
I know princomp() would give the principal components
问题
如何从$ d,$ u和$ v(s = svd(x)
的解)中获取主成分?
How to get the principal components from $d, $u, and $v (solution of s = svd(x)
)?
推荐答案
您可能应该研究prcomp
,它使用svd
而不是eigen
来计算PCA(如princomp
所示) .这样,如果您想要的只是PCA输出,但使用svd
计算得出的结果,您将很高兴.
One way or another, you should probably look into prcomp
, which calculates PCA using svd
instead of eigen
(as in princomp
). That way, if all you want is the PCA output, but calculated using svd
, you're golden.
此外,如果您在命令行中键入stats:::prcomp.default
,则可以自己查看它如何使用svd
的输出.
Also, if you type stats:::prcomp.default
at the command line, you can see how it's using the output of svd
yourself.
这篇关于在R中比较svd和princomp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!