本文介绍了无法从princomp生成分数,无法生成双线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我想使用不是由princomp
本身生成的协方差或相关矩阵时,我遇到了princomp
的问题,特别是biplot
.为简单起见,我将使用比我要处理的数据集小的数据集.
I am having issues with princomp
, specifically biplot
, when I want to use a covariance or correlation matrix not generated by princomp
itself. For simplicity I will use a much smaller dataset than the one I am dealing with.
cr <- cov.wt(USArrests)
biplot(princomp(data = USArrests, covmat = cr))
给我错误
Error in biplot.princomp(princomp(data = USArrests, covmat = cr)) :
object 'princomp(data = USArrests, covmat = cr)' has no scores
似乎在这里发生了一些简单的事情,但到目前为止,谷歌一直无济于事.
Seems like something simple going on here, but google has thus far been unhelpful.
推荐答案
princomp
中的data
参数只能由类'formula'的S3方法"使用.因此,您需要通过以下两种方式之一来指定princomp
调用:
The data
argument in princomp
can only be used by the "S3 method for class 'formula'". Thus, you need to specify your princomp
call in either of these two ways:
cr <- cov.wt(USArrests)
pr1 <- princomp(x = USArrests, covmat = cr)
pr2 <- princomp(formula = ~ ., data = USArrests, covmat = cr)
biplot(pr1)
biplot(pr2)
这篇关于无法从princomp生成分数,无法生成双线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!