Extract weights / weights in ACP / PCA psych :: main

1

I am conducting a Principal Components Analysis (ACP) in R to summarize the monthly correlation patterns found in 30 sampled regions. To do this, I am using as input an array of 10 (months) x 30 (regions) -download here -. At first I was working with the function psych::principal , but when entering the matrix I get the following error:

pc <- principal(dat,nfactors = 2, residuals = FALSE, rotate="varimax", n.obs=NA, covar=TRUE,scores=TRUE, missing=FALSE, impute="median", oblique.scores=TRUE, method="regression")
  

Warning messages: 1: In cor.smooth (r): Matrix was not positive   definite, smoothing was done 2: Main (dat): The matrix is   not positive semi-definite, scores found from Structure loadings

The function is executed, the problem is that pc $ weights is the same as pc $ loadings. When the matrix is square, or the number of columns is less than that of the rows, the weights are obtained without problem, however, it is not the case of my data.

The function principal , using the sample data of the function, allows me to directly extract the loadings , scores and weights . It is important to extract the weights of the main components because I need to express the scores in the same correlation unit as the input variable.

I have tried the function stats::prcomp with my data and it does not alert me of any error, but it does not return at a glance the weights as they are defined in principal .

I thank you in advance for any help provided. Thank you.

    
asked by Marina 26.04.2018 в 16:56
source

1 answer

1

Clarification

Looking at it more closely, your data is a correlation between months and x102 ... x607 , but no is a matrix of correlations, which should be square and have the same variables in rows and columns. Then covar = FALSE would be right. In that case, principal would calculate the correlation matrix of the correlations of the columns x102 ... x607 and make the PCA on that matrix. Is it what you are looking for? Regardless of the weights problem

Matching loadings and weights with principal

Reviewing the (very unfriendly) documentation of psych link in the paragraph principal I read that

  

The regression weights are found from the inverse of the correlation matrix times the component loadings. [p. 302]

And seeing the code of the function I find this line:

if (scores && raw) {
    result$weights <- try(solve(r, result$Structure), silent = TRUE)
    if (class(result$weights) == "try-error") {
        warning("The matrix is not positive semi-definite, scores found from Structure loadings")
        result$weights <- result$Structure
    }

Which is the one that produces the 2nd warning of your code and is the only part of the code that produces that warning, so it's sure that this is the if that is running.

What does line mean? If you can not calculate the inverse of r and Structure , return Structure and issue a warning very little informative. That's why in your case weights and charges coincide.

  

Note: solve() resolves the inverse of two matrices.

I'm not completely sure, but I think you should have raw raw data to be able to do what you're looking for. That is, no correlations in months and the other variables, but direct measurements.

prcomp

According to the documentation of this function weights is not within the output it produces. You could calculate it by doing the inverse of the correlations and charges matrix, but you should have the same error as in principal .

I regret that there is no easy solution to the problem.

PS: it could also be a bugs in psych . He has them in heaps.

    
answered by 27.04.2018 / 17:48
source