Working with log-ratio coordinates in coda.base

Marc Comas-Cufí


In this vignette we show how to define log-ratio coordinates using coda.base package and its function coordinates with parameters X, a composition, and basis, defining the independent log-contrasts for building the coordinates.

In this vignette we work with a subcomposition of the results obtained in different regions of Catalonia in 2017’s parliament elections:

# By default basis is not shown, in this vignette we turn on basis showing.
options('coda.base.basis' = TRUE)
X = parliament2017[,c('erc','jxcat','psc','cs')]

Defining classical log-ratio coordinates with coda.base

The additive logratio (alr) coordinates

The alr coordinates are accessible by setting the parameter basis='alr' or by using the building function alr_basis().

If you don’t want the last part in the denominator, the easiest way to define an alr-coordinates is to set basis='alr':

It defines an alr-coordinates were the first parts are used for the numerator of the log-quotient in order and the last part is used in the denominator.

The basis can be reproduced using the function alr_basis:

In fact, function alr_basis allows to define any type of alr-like coordinate by defining the numerator and the denominator:

The log-contrast matrix can be used in basis parameter:

The centered logratio (clr) coordinates

Building centered log-ratio coordinates can be accomplished by setting parameter basis='clr':

The isometric logratio (ilr) coordinates

coda.base allows to define a wide variety of ilr-coordinates: principal components (pc) coordinates, specific user balances coordinates, principal balances (pb) coordinates, balanced coordinates (default’s CoDaPack’s coordinates).

The default ilr coordinate used by coda.base are accessible by simply calling function coordinates without parameters:

Parameter basis is set to ilr by default:

Other ilr-coordinates: Principal Components and Principal balances

Other easily accessible coordinates are the Principal Component (PC) coordinates. PC coordinates define the first coordinate as the log-contrast with highest variance, the second the one independent from the first and with highest variance and so on:

Note that the PC coordinates are independent:

The Principal Balance coordinates are similar to PC coordinates but with the restriction that the log contrast are balances

Moreover, they are not independent:

Principal Balances are hard to compute when the number of components is very high. coda.base allows to build PB approximations using different algorithms.

We can compare they performance (variance explained by the first balance) with respect to the principal components.

Finally, coda.base allows to define the default CoDaPack basis which consists in defining well balanced balances, i.e. equal number of branches in each balance.

Defining coordinates manually

Defining coordinates with an specific basis

We can define the coordinates directly by providing the log-contrast matrix.

Defining coordinates using balances

We can also define balances using formula numerator~denominator:

With sbp_basis we do not need to define neither a basis nor a system generator


We can also define sequential binary partition using a matrix.