Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You want the <code>$loadings</code> component of the returned object:</p> <pre><code>R&gt; class(pca$loadings) [1] "loadings" R&gt; pca$loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 a -0.198 0.713 -0.671 b 0.600 0.334 -0.170 0.707 c -0.600 -0.334 0.170 0.707 d 0.439 -0.880 -0.180 e 0.221 0.701 0.678 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 SS loadings 1.0 1.0 1.0 1.0 1.0 Proportion Var 0.2 0.2 0.2 0.2 0.2 Cumulative Var 0.2 0.4 0.6 0.8 1.0 </code></pre> <p>Note that this has a special <code>print()</code> method which suppresses <em>printing</em> of small loadings.</p> <p>If you want this as a relative contribution then sum up the loadings per column and express each loading as a proportion of the column (loading) sum, taking care to use the absolute values to account for negative loadings.</p> <pre><code>R&gt; load &lt;- with(pca, unclass(loadings)) R&gt; load Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 a -0.1980087 0.712680378 0.04606100 -0.6713848 0.000000e+00 b 0.5997346 -0.014945831 0.33353047 -0.1698602 7.071068e-01 c -0.5997346 0.014945831 -0.33353047 0.1698602 7.071068e-01 d 0.4389388 0.009625746 -0.88032515 -0.1796321 5.273559e-16 e 0.2208215 0.701104321 -0.02051507 0.6776944 -1.110223e-16 </code></pre> <p>This final step then yields the proportional contribution to the each principal component</p> <pre><code>R&gt; aload &lt;- abs(load) ## save absolute values R&gt; sweep(aload, 2, colSums(aload), "/") Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 a 0.09624979 0.490386943 0.02853908 0.35933068 0.000000e+00 b 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01 c 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01 d 0.21336314 0.006623362 0.54544349 0.09614059 3.728970e-16 e 0.10733880 0.482421595 0.01271100 0.36270762 7.850462e-17 R&gt; colSums(sweep(aload, 2, colSums(aload), "/")) Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 1 1 1 1 1 </code></pre> <hr> <p>If using the preferred <code>prcomp()</code> then the relevant loadings are in the <code>$rotation</code> component:</p> <pre><code>R&gt; pca2 &lt;- prcomp(my_table, scale = TRUE) R&gt; pca2$rotation PC1 PC2 PC3 PC4 PC5 a -0.1980087 0.712680378 -0.04606100 -0.6713848 0.000000e+00 b 0.5997346 -0.014945831 -0.33353047 -0.1698602 -7.071068e-01 c -0.5997346 0.014945831 0.33353047 0.1698602 -7.071068e-01 d 0.4389388 0.009625746 0.88032515 -0.1796321 -3.386180e-15 e 0.2208215 0.701104321 0.02051507 0.6776944 5.551115e-17 </code></pre> <p>And the relevant incantation is now:</p> <pre><code>R&gt; aload &lt;- abs(pca2$rotation) R&gt; sweep(aload, 2, colSums(aload), "/") PC1 PC2 PC3 PC4 PC5 a 0.09624979 0.490386943 0.02853908 0.35933068 0.000000e+00 b 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01 c 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01 d 0.21336314 0.006623362 0.54544349 0.09614059 2.394391e-15 e 0.10733880 0.482421595 0.01271100 0.36270762 3.925231e-17 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload