scores not being generated from princomp, unable to generate biplot

你离开我真会死。 提交于 2019-12-11 10:57:24

问题


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))

gives me the error

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.


回答1:


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)


来源:https://stackoverflow.com/questions/18752899/scores-not-being-generated-from-princomp-unable-to-generate-biplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!