简体   繁体   中英

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. Is there a function within this package that I'm not aware of (I have very, very little R experience)??

NOTE: I've been simply working in the command line.

Error for scree(PCA):

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

Error for 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?

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.

  1. Try get help on scree function. Are you missing a parameter? Type in command line. help(scree)

  2. Look at your variable PCA

    head(PCA) - shows first few rows of your data

    str(PCA) - shows structure of the variable. Is it what scree function is expecting?

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

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

Hope this gets you on track.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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