# princompaplus: Principal component analysis for amounts in log geometry In compositions: Compositional Data Analysis

## Description

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

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```## S3 method for class 'aplus' princomp(x,...,scores=TRUE,center=attr(covmat,"center"), covmat=var(x,robust=robust,giveCenter=TRUE), robust=getOption("robust")) ## S3 method for class 'princomp.aplus' print(x,...) ## S3 method for class 'princomp.aplus' 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.aplus' predict(object,newdata,...) ```

## Arguments

 `x` an aplus dataset (for princomp) or a result from princomp.aplus `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 when plotting the loadings `main` title of the plot `object` a fitted princomp.aplus object `newdata` another amount dataset of class aplus `...` 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 `var.rmult` for details.

## Details

As a metric euclidean space, the positive real space described in `aplus` has its own principal component analysis, that can be performed either in terms of the covariance matrix or the correlation matrix. However, since all parts in a composition or in an amount vector share a natural scaling, they do not need the standardization (which in fact would produce a loss of important information). For this reason, `princomp.aplus` works on the covariance matrix.
To aid the interpretation we added some extra functionality to a normal `princomp(ilt(x))`. First of all the result contains as additional information the amount representation of returned vectors in the space of the data: the center as an amount `Center`, and the loadings in terms of amounts to perturbe with, either positively (`Loadings`) or negatively (`DownLoadings`). The Up- and DownLoadings are normalized to the number of parts and not to one to simplify the interpretation. A value of about one means no change in the specific component.
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 the biplot uses, additionally to the classical one, a compositional concept: The differences between two arrowheads can be interpreted as log-ratios between the two components represented by the arrows.
The amount loading plot is introduced with this package. The loadings of all component can be seen as an orthogonal basis in the space of `ilt`-transformed data. These vectors are displayed by a barplot with their corresponding amounts. A portion of one means no change of this part. This is equivalent to 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 amount vector being represented by the unit vector of loadings in the ilt-transformed space. If `scale.sdev` is numeric we use this amount vector 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. The interpretation of the ratios plot may only be done in an Aitchison-compositional framework (see `princomp.acomp`).

## 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"`. `center` the ilt-transformed vector of means used to center the dataset `Center` the `aplus` 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` vectors of amounts that represent a perturbation with the vectors represented by the loadings of each of the factors `DownLoadings` vectors of amounts that represent a perturbation with the inverses 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

`ilt`,`aplus`, `relativeLoadings` `princomp.acomp`, `princomp.rplus`, `barplot.aplus`, `mean.aplus`,

## 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(aplus(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

Warning message:
In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Call:
princomp.aplus(x = aplus(sa.lognormals5))

Standard deviations:
Comp.1    Comp.2    Comp.3    Comp.4    Comp.5
2.8959742 1.3668889 0.9197838 0.4700715 0.2663837

5  variables and  60 observations.
Mean (compositional):
Cu         Zn         Pb         Cd         Co
3.2669025  8.4988046 15.7466498  0.1176520  0.1236904
attr(,"class")
[1] aplus
Cu        Zn        Pb        Cd        Co
Comp.1 0.9508691 0.9445919 0.9876193 2.0323883 2.0153007
Comp.2 0.5399493 0.5220631 1.5521695 0.9714872 0.9416861
Comp.3 0.7554872 0.7148647 0.4076028 0.9935220 0.9447465
Comp.4 2.0749626 0.5071282 1.0232480 0.9475488 1.0535653
Comp.5 0.9241393 1.0247031 0.9761420 0.4954403 2.0271974
attr(,"class")
[1] aplus
Cu        Zn        Pb        Cd       Co
Comp.1 1.0516695 1.0586583 1.0125359 0.492032 0.4962039
Comp.2 1.8520256 1.9154773 0.6442595 1.029350 1.0619250
Comp.3 1.3236492 1.3988661 2.4533688 1.006520 1.0584850
Comp.4 0.4819364 1.9718880 0.9772802 1.055355 0.9491581
Comp.5 1.0820880 0.9758924 1.0244411 2.018407 0.4932919
attr(,"class")
[1] aplus
Importance of components:
Comp.1    Comp.2     Comp.3     Comp.4      Comp.5
Standard deviation     2.8959742 1.3668889 0.91978383 0.47007151 0.266383725
Proportion of Variance 0.7361257 0.1639944 0.07425644 0.01939503 0.006228421
Cumulative Proportion  0.7361257 0.9001201 0.97437655 0.99377158 1.000000000
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Cu        -0.616 -0.280  0.730
Zn        -0.650 -0.336 -0.679
Pb         0.440 -0.897
Cd  0.709                      -0.702
Co  0.701                       0.707

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
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Cu/Zn                      4.09   0.90
Cu/Pb        0.35   1.85   2.03
Zn/Pb        0.34   1.75   0.50
Cu/Cd 0.47   0.56   0.76   2.19   1.87
Zn/Cd 0.46   0.54   0.72   0.54   2.07
Pb/Cd 0.49   1.60   0.41          1.97
Cu/Co 0.47   0.57   0.80   1.97   0.46
Zn/Co 0.47   0.55   0.76   0.48   0.51
Pb/Co 0.49   1.65   0.43          0.48
Cd/Co                      0.90   0.24
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Cu/Zn                      4.09   0.90
Cu/Pb        0.35   1.85   2.03
Zn/Pb        0.34   1.75   0.50
Cu/Cd 0.47   0.56   0.76   2.19   1.87
Zn/Cd 0.46   0.54   0.72   0.54   2.07
Pb/Cd 0.49   1.60   0.41          1.97
Cu/Co 0.47   0.57   0.80   1.97   0.46
Zn/Co 0.47   0.55   0.76   0.48   0.51
Pb/Co 0.49   1.65   0.43          0.48
Cd/Co                      0.90   0.24
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Cu/Zn                      1.94
Cu/Pb 0.90   0.24   1.76   1.39
Zn/Pb 0.88   0.23   1.68   0.72
Cu/Cd 0.11   0.45   0.78   1.45   1.18
Zn/Cd 0.11   0.43   0.74   0.75   1.21
Pb/Cd 0.12   1.90   0.44          1.20
Cu/Co 0.11   0.47   0.81   1.38   0.81
Zn/Co 0.11   0.45   0.77   0.71   0.83
Pb/Co 0.13   1.98   0.46          0.82
Cd/Co                             0.69
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Cu/Zn               1.107  3.761
Cu/Pb 0.803  0.056  3.112  1.944
Zn/Pb 0.773  0.051  2.811  0.517
Cu/Cd 0.012  0.201  0.604  2.089  1.394
Zn/Cd 0.012  0.183  0.546  0.556  1.473
Pb/Cd 0.015  3.600  0.194         1.435
Cu/Co 0.013  0.219  0.663  1.891  0.658
Zn/Co 0.012  0.199  0.599  0.503  0.695
Pb/Co 0.016  3.920  0.213         0.677
Cd/Co                             0.472
Warning messages:
1: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
2: In structure(c(), class = c(class(x), class(y))) :
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
Consider 'structure(list(), *)' instead.
Cu        Zn        Pb        Cd        Co
Comp.1 0.9508691 0.9445919 0.9876193 2.0323883 2.0153007
Comp.2 0.5399493 0.5220631 1.5521695 0.9714872 0.9416861
Comp.3 0.7554872 0.7148647 0.4076028 0.9935220 0.9447465
Comp.4 2.0749626 0.5071282 1.0232480 0.9475488 1.0535653
Comp.5 0.9241393 1.0247031 0.9761420 0.4954403 2.0271974
attr(,"class")
[1] aplus
Cu        Zn        Pb        Cd       Co
Comp.1 1.0516695 1.0586583 1.0125359 0.492032 0.4962039
Comp.2 1.8520256 1.9154773 0.6442595 1.029350 1.0619250
Comp.3 1.3236492 1.3988661 2.4533688 1.006520 1.0584850
Comp.4 0.4819364 1.9718880 0.9772802 1.055355 0.9491581
Comp.5 1.0820880 0.9758924 1.0244411 2.018407 0.4932919
attr(,"class")
[1] aplus
Comp.1     Comp.2     Comp.3     Comp.4     Comp.5
8.38666680 1.86838523 0.84600229 0.22096722 0.07096029
Comp.1       Comp.2        Comp.3        Comp.4        Comp.5
Comp.1  8.386667e+00 8.807636e-16 -8.123541e-16  8.615374e-16 -4.594252e-16
Comp.2  8.807636e-16 1.868385e+00  2.418950e-16  9.018274e-16  1.993820e-16
Comp.3 -8.123541e-16 2.418950e-16  8.460023e-01 -2.764261e-16  2.365458e-16
Comp.4  8.615374e-16 9.018274e-16 -2.764261e-16  2.209672e-01  2.376429e-16
Comp.5 -4.594252e-16 1.993820e-16  2.365458e-16  2.376429e-16  7.096029e-02
```

compositions documentation built on May 30, 2017, 3:25 a.m.