# princompacomp: Principal component analysis for Aitchison compositions In compositions: Compositional Data Analysis

## Description

A principal component analysis is done in the Aitchison geometry (i.e. clr-transform) of the simplex. Some gimics simplify the interpretation of the computed components as compositional perturbations.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ``` ## S3 method for class 'acomp' princomp(x,...,scores=TRUE,center=attr(covmat,"center"), covmat=var(x,robust=robust,giveCenter=TRUE), robust=getOption("robust")) ## S3 method for class 'princomp.acomp' print(x,...) ## S3 method for class 'princomp.acomp' plot(x,y=NULL,..., npcs=min(10,length(x\$sdev)), type=c("screeplot","variance","biplot","loadings","relative"), main=NULL,scale.sdev=1) ## S3 method for class 'princomp.acomp' predict(object,newdata,...) ```

## Arguments

 `x` a acomp-dataset (in princomp) or a result from princomp.acomp `y` not used `scores` a logical indicating whether scores should be computed or not `npcs` the number of components to be drawn in the scree plot `type` type of the plot: `"screeplot"` is a lined screeplot, `"variance"` is a boxplot-like screeplot, `"biplot"` is a biplot, `"loadings"` displays the loadings as a `barplot.acomp` `scale.sdev` the multiple of sigma to use plotting the loadings `main` title of the plot `object` a fitted princomp.acomp object `newdata` another compositional dataset of class acomp `...` further arguments to pass to internally-called functions `covmat` provides the covariance matrix to be used for the principle component analysis `center` provides the be used for the computation of scores `robust` Gives the robustness type for the calculation of the covariance matrix. See `robustnessInCompositions` for details.

## Details

As a metric euclidean space the Aitchison simplex has its own principal component analysis, that should be performed in terms of the covariance matrix and not in terms of the meaningless correlation matrix.
To aid the interpretation we added some extra functionality to a normal `princomp(clr(x))`. First of all the result contains as additional information the compositional representation of the returned vectors in the space of the data: the center as a composition `Center`, and the loadings in terms of a composition to perturbe with, either positively (`Loadings`) or negatively (`DownLoadings`). The Up- and DownLoadings are normalized to the number of parts in the simplex and not to one to simplify the interpretation. A value of about one means no change in the specific component. To avoid confusion the meaningless last principal component is removed.
The `plot` routine provides screeplots (`type = "s"`,```type= "v"```), biplots (`type = "b"`), plots of the effect of loadings (`type = "b"`) in `scale.sdev*sdev`-spread, and loadings of pairwise (log-)ratios (`type = "r"`).
The interpretation of a screeplot does not differ from ordinary screeplots. It shows the eigenvalues of the covariance matrix, which represent the portions of variance explained by the principal components.
The interpretation of the biplot strongly differs from a classical one. The relevant variables are not the arrows drawn (one for each component), but rather the links (i.e., the differences) between two arrow heads, which represents the log-ratio between the two components represented by the arrows.
The compositional loading plot is introduced with this package. The loadings of all component can be seen as an orthogonal basis in the space of clr-transformed data. These vectors are displayed by a barplot with their corresponding composition. For a better interpretation the total of these compositons is set to the number of parts in the composition, such that a portion of one means no effect. This is similar to (but not exactly the same as) a zero loading in a real principal component analysis.
The loadings plot can work in two different modes: if `scale.sdev` is set to `NA` it displays the composition beeing represented by the unit vector of loadings in the clr-transformed space. If `scale.sdev` is numeric we use this composition scaled by the standard deviation of the respective component.
The relative plot displays the `relativeLoadings` as a barplot. The deviation from a unit bar shows the effect of each principal component on the respective ratio.

## Value

`princomp` gives an object of type `c("princomp.acomp","princomp")` with the following content:

 `sdev` the standard deviation of the principal components `loadings` the matrix of variable loadings (i.e., a matrix which columns contain the eigenvectors). This is of class `"loadings"`. The last eigenvector is removed since it should contain the irrelevant scaling. `center` the clr-transformed vector of means used to center the dataset `Center` the `acomp` vector of means used to center the dataset `scale` the scaling applied to each variable `n.obs` number of observations `scores` if `scores = TRUE`, the scores of the supplied data on the principal components. Scores are coordinates in a basis given by the principal components and thus not compositions `call` the matched call `na.action` not clearly understood `Loadings` compositions that represent a perturbation with the vectors represented by the loadings of each of the factors `DownLoadings` compositions that represent a perturbation with the inverse of the vectors represented by the loadings of each of the factors

`predict` returns a matrix of scores of the observations in the `newdata` dataset
. The other routines are mainly called for their side effect of plotting or printing and return the object `x`.

## Author(s)

K.Gerald v.d. Boogaart http://www.stat.boogaart.de

## References

Aitchison, J, C. Barcel'o-Vidal, J.J. Egozcue, V. Pawlowsky-Glahn (2002) A consise guide to the algebraic geometric structure of the simplex, the sample space for compositional data analysis, Terra Nostra, Schriften der Alfred Wegener-Stiftung, 03/2003

Aitchison, J. and M. Greenacre (2002) Biplots for Compositional Data Journal of the Royal Statistical Society, Series C (Applied Statistics) 51 (4) 375-392

`clr`,`acomp`, `relativeLoadings` `princomp.aplus`, `princomp.rcomp`, `barplot.acomp`, `mean.acomp`, `var.acomp`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26``` ```data(SimulatedAmounts) pc <- princomp(acomp(sa.lognormals5)) pc summary(pc) plot(pc) #plot(pc,type="screeplot") plot(pc,type="v") plot(pc,type="biplot") plot(pc,choice=c(1,3),type="biplot") plot(pc,type="loadings") plot(pc,type="loadings",scale.sdev=-1) # Downward plot(pc,type="relative",scale.sdev=NA) # The directions plot(pc,type="relative",scale.sdev=1) # one sigma Upward plot(pc,type="relative",scale.sdev=-1) # one sigma Downward biplot(pc) screeplot(pc) loadings(pc) relativeLoadings(pc,mult=FALSE) relativeLoadings(pc) relativeLoadings(pc,scale.sdev=1) relativeLoadings(pc,scale.sdev=2) pc\$Loadings pc\$DownLoadings barplot(pc\$Loadings) pc\$sdev^2 cov(predict(pc,sa.lognormals5)) ```

### Example output

```Loading required package: tensorA

Attaching package: 'tensorA'

The following object is masked from 'package:base':

norm

Welcome to compositions, a package for compositional data analysis.
Find an intro with "? compositions"

Attaching package: 'compositions'

The following objects are masked from 'package:stats':

cor, cov, dist, var

The following objects are masked from 'package:base':

%*%, scale, scale.default

Call:
princomp.acomp(x = acomp(sa.lognormals5))

Standard deviations:
Comp.1    Comp.2    Comp.3    Comp.4
2.4446654 1.2633257 0.4712606 0.2690160

5  variables and  60 observations.
Mean (compositional):
Cu          Zn          Pb          Cd          Co
0.117710525 0.306222405 0.567371204 0.004239147 0.004456718
attr(,"class")
[1] acomp
Cu        Zn        Pb        Cd        Co
Comp.1 0.6068998 0.5985836 0.6809203 1.5692975 1.5442987
Comp.2 1.3189309 1.3440242 0.3936868 0.9642938 0.9790643
Comp.3 1.8475861 0.4506335 0.8975793 0.8601707 0.9440304
Comp.4 0.8563030 0.9394475 0.9110133 0.4496577 1.8435786
attr(,"class")
[1] acomp
Cu        Zn        Pb        Cd        Co
Comp.1 1.3568839 1.3757353 1.2093816 0.5247523 0.5332469
Comp.2 0.6213931 0.6097915 2.0817934 0.8499221 0.8370999
Comp.3 0.4439141 1.8200368 0.9137572 0.9534962 0.8687957
Comp.4 0.9578058 0.8730365 0.9002854 1.8239920 0.4448804
attr(,"class")
[1] acomp
Importance of components:
Comp.1    Comp.2     Comp.3      Comp.4
Standard deviation     2.444665 1.2633257 0.47126060 0.269016049
Proportion of Variance 0.759694 0.2028759 0.02823073 0.009199331
Cumulative Proportion  0.759694 0.9625699 0.99080067 1.000000000

Comp.1 Comp.2 Comp.3 Comp.4
Cu -0.397  0.360  0.714
Zn -0.411  0.379 -0.697
Pb -0.282 -0.849
Cd  0.553               -0.700
Co  0.537                0.711

Comp.1 Comp.2 Comp.3 Comp.4
Proportion Var    0.2    0.2    0.2    0.2
Cumulative Var    0.2    0.4    0.6    0.8
Comp.1 Comp.2 Comp.3 Comp.4
Cu/Zn               4.10
Cu/Pb 0.89   3.35   2.06
Zn/Pb 0.88   3.41   0.50
Cu/Cd 0.39   1.37   2.15   1.90
Zn/Cd 0.38   1.39   0.52   2.09
Pb/Cd 0.43   0.41          2.03
Cu/Co 0.39   1.35   1.96   0.46
Zn/Co 0.39   1.37   0.48   0.51
Pb/Co 0.44   0.40          0.49
Cd/Co                      0.24
Comp.1 Comp.2 Comp.3 Comp.4
Cu/Zn               4.10
Cu/Pb 0.89   3.35   2.06
Zn/Pb 0.88   3.41   0.50
Cu/Cd 0.39   1.37   2.15   1.90
Zn/Cd 0.38   1.39   0.52   2.09
Pb/Cd 0.43   0.41          2.03
Cu/Co 0.39   1.35   1.96   0.46
Zn/Co 0.39   1.37   0.48   0.51
Pb/Co 0.44   0.40          0.49
Cd/Co                      0.24
Comp.1 Comp.2 Comp.3 Comp.4
Cu/Zn               1.944
Cu/Pb 0.755  4.606  1.405
Zn/Pb 0.730  4.717  0.723
Cu/Cd 0.098  1.485  1.434  1.189
Zn/Cd 0.095  1.521  0.737  1.219
Pb/Cd 0.130  0.322         1.209
Cu/Co 0.102  1.457  1.372  0.814
Zn/Co 0.099  1.492  0.706  0.834
Pb/Co 0.135  0.316         0.827
Cd/Co                      0.684
Comp.1  Comp.2  Comp.3  Comp.4
Cu/Zn                  3.7806
Cu/Pb  0.5697 21.2164  1.9747
Zn/Pb  0.5325 22.2512  0.5223
Cu/Cd  0.0096  2.2063  2.0556  1.4142
Zn/Cd  0.0090  2.3139  0.5437  1.4865
Pb/Cd  0.0169  0.1040          1.4621
Cu/Co  0.0104  2.1231  1.8830  0.6619
Zn/Co  0.0097  2.2267  0.4981  0.6958
Pb/Co  0.0182  0.1001          0.6844
Cd/Co                          0.4681
Cu        Zn        Pb        Cd        Co
Comp.1 0.6068998 0.5985836 0.6809203 1.5692975 1.5442987
Comp.2 1.3189309 1.3440242 0.3936868 0.9642938 0.9790643
Comp.3 1.8475861 0.4506335 0.8975793 0.8601707 0.9440304
Comp.4 0.8563030 0.9394475 0.9110133 0.4496577 1.8435786
attr(,"class")
[1] acomp
Cu        Zn        Pb        Cd        Co
Comp.1 1.3568839 1.3757353 1.2093816 0.5247523 0.5332469
Comp.2 0.6213931 0.6097915 2.0817934 0.8499221 0.8370999
Comp.3 0.4439141 1.8200368 0.9137572 0.9534962 0.8687957
Comp.4 0.9578058 0.8730365 0.9002854 1.8239920 0.4448804
attr(,"class")
[1] acomp
Comp.1     Comp.2     Comp.3     Comp.4
5.97638879 1.59599174 0.22208655 0.07236963
Comp.1        Comp.2        Comp.3        Comp.4
Comp.1 5.976389e+00  6.886806e-16  1.318136e-15  7.929331e-17
Comp.2 6.886806e-16  1.595992e+00 -1.364808e-17 -1.323361e-16
Comp.3 1.318136e-15 -1.364808e-17  2.220866e-01  1.549674e-17
Comp.4 7.929331e-17 -1.323361e-16  1.549674e-17  7.236963e-02
```

compositions documentation built on June 14, 2018, 5:03 p.m.