2
$\begingroup$

I have a raster stack of 19 layers called "raster_bio". The code to do PCA analysis is:

vv     <- getValues(raster_bio)
my.prc <- prcomp(na.omit(vv), center=TRUE, scale=TRUE)

# Then I selected first 5 PCs and did varimax rotation.
varima <- varimax(my.prc$rotation[,1:5])

Then I want to use varima, the 5 rotated loadings, to get spatial PCs:

pprc <- predict(raster_bio, varima)

The predict function would not work since "varima" here is not a model. So I tried something else based on the page mentioned in the reply.

> varima
$loadings

Loadings:
      PC1    PC2    PC3    PC4    PC5   
bio1          0.350 -0.275              
bio2                 0.194         0.658
bio3         -0.134 -0.297         0.573
bio4          0.240  0.426              
bio5          0.505                     
bio6          0.141 -0.418              
bio7          0.221  0.430              
bio8  -0.436  0.394 -0.149        -0.187
bio9   0.369  0.163 -0.189         0.275
bio10         0.502                     
bio11         0.145 -0.415              
bio12  0.180                0.361       
bio13                       0.537       
bio14  0.405                            
bio15 -0.291         0.114         0.322
bio16                       0.520       
bio17  0.369                            
bio18 -0.199                0.523       
bio19  0.443                            

                 PC1   PC2   PC3   PC4   PC5
SS loadings    1.000 1.000 1.000 1.000 1.000
Proportion Var 0.053 0.053 0.053 0.053 0.053
Cumulative Var 0.053 0.105 0.158 0.211 0.263

$rotmat
           [,1]         [,2]        [,3]        [,4]       [,5]
[1,]  0.6108976 -0.003008026 -0.62556569  0.45759088 -0.1614720
[2,]  0.2354179  0.818121480 -0.01836594 -0.43651780 -0.2904661
[3,]  0.6128850 -0.321653016  0.63329819 -0.07390564 -0.3382051
[4,] -0.2685337  0.369912143  0.36408301  0.74586160 -0.3196696
[5,]  0.3516307  0.300620258  0.27332622  0.19568143  0.8203565

 > pca_rotated

Principal Components Analysis
Call: psych::principal(r = na.omit(vv), nfactors = 5, rotate = "varimax", 
scores = TRUE)
Standardized loadings (pattern matrix) based upon correlation matrix
    RC1   RC4   RC2   RC3   RC5   h2     u2 com
bio1   0.47  0.01  0.80  0.37 -0.02 1.00 0.0034 2.1
bio2  -0.80 -0.22 -0.22 -0.13  0.46 0.97 0.0327 2.0
bio3  -0.30  0.35 -0.28  0.77  0.29 0.97 0.0332 2.4
bio4  -0.31 -0.45  0.19 -0.80  0.10 1.00 0.0024 2.1
bio5   0.16 -0.35  0.88 -0.26  0.07 1.00 0.0045 1.6
bio6   0.49  0.23  0.50  0.66 -0.08 1.00 0.0025 3.1
bio7  -0.35 -0.45  0.15 -0.80  0.12 1.00 0.0013 2.2
bio8  -0.46 -0.12  0.82 -0.02 -0.21 0.95 0.0531 1.8
bio9   0.77  0.03  0.35  0.43  0.21 0.94 0.0571 2.3
bio10  0.25 -0.29  0.90 -0.17  0.05 0.99 0.0050 1.5
bio11  0.49  0.23  0.50  0.67 -0.06 1.00 0.0022 3.1
bio12  0.63  0.71 -0.12  0.27 -0.01 0.99 0.0111 2.3
bio13  0.37  0.88 -0.14  0.21  0.06 0.98 0.0172 1.5
bio14  0.95  0.21  0.12  0.08  0.05 0.96 0.0355 1.2
bio15 -0.93 -0.09 -0.04 -0.14  0.18 0.93 0.0695 1.1
bio16  0.33  0.89 -0.16  0.26  0.02 0.99 0.0073 1.5
bio17  0.94  0.27  0.08  0.13  0.01 0.97 0.0268 1.2
bio18 -0.04  0.91 -0.20  0.33 -0.11 0.99 0.0127 1.4
bio19  0.97  0.18  0.04  0.08  0.07 0.99 0.0140 1.1

                   RC1  RC4  RC2  RC3  RC5
SS loadings           6.77 3.96 3.85 3.54 0.48
Proportion Var        0.36 0.21 0.20 0.19 0.03
Cumulative Var        0.36 0.57 0.77 0.95 0.98
Proportion Explained  0.36 0.21 0.21 0.19 0.03
Cumulative Proportion 0.36 0.58 0.78 0.97 1.00

Mean item complexity =  1.9
Test of the hypothesis that 5 components are sufficient.

The root mean square of the residuals (RMSR) is  0.01 
 with the empirical chi square  32.94  with prob <  1 

Fit based upon off diagonal values = 1> 

The objective for me to do the rotation is to see simplified relationship of PCs and bioclimatic variables. In the first part of my code, I did the varimax rotation on eigenvalues, and the correlation matrix seem to do what I want. But by using "psych::principal", the Standardized loadings (pattern matrix) based upon correlation matrix does not show simplified relationships. I'm confused about the difference to these.

And based on the youtube video:https://www.youtube.com/watch?v=oZ2nfIPdvjY The varimax rotation was done without scaling the loadings.

So my questions is: 1. how can I get simplified relationship of PCs and bioclimatic variables using rotation correctly? 2. how to get a raster surface of PC other than matrix?

I used to do that in Arcgis which does not give me much control over the process. I appreciate any comment. Thanks a lot! The question is edited. Since the differences is that I got rows of data entry from the raster. But in the end, I want to get a raster surface of the PCs.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.