简体   繁体   English

带有 psych 包的 R 中的 Screeplot

[英]Screeplot in R with psych package

I have computed a PCA with the principal function in the psych package in R. I would like to build a screeplot from the eigenvalues, but both scree(PCA) and screeplot(PCA) give me errors and no plot.我已经用 R 中的 psych 包中的主要函数计算了一个 PCA。我想从特征值构建一个 screeplot,但是 scree(PCA) 和 screeplot(PCA) 都给我错误并且没有情节。 Is there a function within this package that I'm not aware of (I have very, very little R experience)??这个包中是否有我不知道的功能(我的 R 经验非常非常少)??

NOTE: I've been simply working in the command line.注意:我一直只是在命令行中工作。

Error for scree(PCA):屏幕错误(PCA):

Error in if (nvar != dim(rx)[1]) { : argument is of length zero

Error for screeplot(PCA): screeplot(PCA) 的错误:

Error in plot.window(xlim, ylim, log = log, ...) : 
need finite 'xlim' values
In addition: Warning messages:
1: In min(w.l) : no non-missing arguments to min; returning Inf
2: In max(w.r) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf

Did you enter a correlation matrix as your input to the scree( ) function?您是否输入了相关矩阵作为scree( )函数的输入?

Using my own data, I was able to generate a scree plot with the following two lines of code:使用我自己的数据,我能够用以下两行代码生成一个碎石图:

humor_cor <- cor(humor, use = "pairwise.complete.obs") 
scree(humor_cor, factors = FALSE) 

Without data it is hard for us to check this.没有数据,我们很难检查这一点。 The error message looks like the data is empty.错误消息看起来像数据是空的。

Here are some tips for R beginners.这里有一些给 R 初学者的提示。

  1. Try get help on scree function.尝试获取有关 scree 功能的帮助。 Are you missing a parameter?您是否缺少参数? Type in command line.在命令行中输入。 help(scree)

  2. Look at your variable PCA看看你的变量 PCA

    head(PCA) - shows first few rows of your data head(PCA) - 显示数据的前几行

    str(PCA) - shows structure of the variable. str(PCA) - 显示变量的结构。 Is it what scree function is expecting?它是什么 scree 功能所期望的?

  3. Do you have missing values or text values in your data?您的数据中是否有缺失值或文本值? The function may be thrown out by these.该函数可能会被这些抛出。 You can drop missing data - take a look at complete.cases .您可以删除丢失的数据 - 看看complete.cases is.na() is how you check for NA values (ie if I wanted to check for NAs in variable mydata , sum(is.na(mydata)) would tell me how many I have. Drop those rows and see if that gets your scree function working okay. is.na()是您检查 NA 值的方式(即,如果我想检查变量mydata NA, sum(is.na(mydata))会告诉我我有多少。删除这些行,看看是否得到您的 scree 功能工作正常。

  4. Take a look at the vignette for the package: https://cran.r-project.org/web/packages/psych/vignettes/overview.pdf看看包的小插图: https : //cran.r-project.org/web/packages/psych/vignettes/overview.pdf

Hope this gets you on track.希望这能让你走上正轨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM