Compositional Data Analysis

Methods for analysis of compositional data including robust methods (), imputation of missing values (), methods to replace rounded zeros (, , ), count zeros (), methods to deal with essential zeros (), (robust) outlier detection for compositional data, (robust) principal component analysis for compositional data, (robust) factor analysis for compositional data, (robust) discriminant analysis for compositional data (Fisher rule), robust regression with compositional predictors, functional data analysis () and p-splines (), contingency () and compositional tables (, , ) and (robust) Anderson-Darling normality tests for compositional data as well as popular log-ratio transformations (addLR, cenLR, isomLR, and their inverse transformations). In addition, visualisation and diagnostic tools are implemented as well as high and low-level plot functions for the ternary diagram.

Robust Methods for Compositional Data

using robCompositions


p1 <- pcaCoDa(expenditures)



What is it?

  • Imputation of compositional data including robust methods, methods to impute rounded zeros
  • Outlier detection for compositional data using robust methods
  • Principal component analysis for compositional data using robust methods
  • Factor analysis for compositional data using robust methods
  • Discriminant analysis for compositional data (Fisher rule) using robust methods
  • Robust regression with compositional predictors
  • Anderson-Darling normality tests for compositional data
  • log-ratio transformations (addLR, cenLR, isomLR, and their inverse transformations).
  • In addition, visualisation and diagnostic tools are implemented as well as high and low-level plot functions for the ternary diagram.


  • never use classical statistical methods on raw compositional data again.

Getting Started

The package has dependencies on

R (>= 2.10), utils, robustbase, rrcov, car (>= 2.0-0), MASS, pls


Installion of robCompositions is really easy for registered users (when the R-tools are installed). Just use

install_github("robCompositions", "matthias-da")


k nearest neighbor imputation



expenditures[1,3] <- NA


iterative model based imputation


x <- expenditures


x[1,3] <- NA

xi <- impCoda(x)$xImp


s1 <- sum(x[1,-3])

impS <- sum(xi[1,-3])

xi[,3] * s1/impS

xi <- impKNNa(expenditures)



plot(xi, which=1)

plot(xi, which=2)

plot(xi, which=3)



p1 <- pcaCoDa(expenditures)



outlier detection


oD <- outCoDa(expenditures)





x <- arcticLake

x.alr <- addLR(x, 2)

y <- addLRinv(x.alr)

addLRinv(addLR(x, 3))


x <- expenditures

y <- addLRinv(addLR(x, 5))



addLRinv(x.alr, ivar=2, useClassInfo=FALSE)


eclr <- cenLR(expenditures)

inveclr <- cenLRinv(eclr)





Sigma <- matrix(c(5.05,4.95,4.95,5.05), ncol=2, byrow=TRUE)

z <- isomLRinv(mvrnorm(100, mu=c(0,2), Sigma=Sigma))


Changes in robCompositions version 2.1.0

  • new functions cubeCoord, cubeCoordWrapper, tabCoord, tabCoordWrapper
  • new data set employment2
  • new data set manu_abs

Changes in robCompositions version 2.0.10

  • updated documentation
  • going back to old version of imputeBDLs
  • mcd based robust variation (instead of mad) in function variation

Changes in robCompositions version 2.0.9

  • new method in imputeBDLs
  • minor change in imputeBDLs
  • new function imputeUDLs

Changes in robCompositions version 2.0.8

  • old Rd files management to meet new CRAN policy

Changes in robCompositions version 2.0.7

  • bug in daFisher resolved
  • additional argment in missPattern
  • imputeBDLs now includes a new method

Changes in robCompositions version 2.0.6

  • new method for imputation of rounded zeros in imputeBDLs

Changes in robCompositions version 2.0.5

  • improved documentation
  • version of robCompositions fits now to the Springer book
  • orthbasis now times -1
  • ilr.2x2 now fits to the formulas in the book, and not for the paper
  • bug in daFisher resolved
  • bug in external variables in pcaCoDa solved
  • registering C-code

Changes in robCompositions version 2.0.4

  • aDist now again works for vectors
  • added following data sets: socExp, cancerMN, educFM, electionATbp, employment, employment_df, GDPsatis, govexp, instw, isic32, mortality_tab, precipitation,
    rcodes, teachingStuff, unemployed
  • corrected documentation for ageCatWorld data
  • new functions: coord, gmean, gmean_sum, ilr.2x2, ind2x2, indTab, int2x2, indTab, int2x2, intArray, intTab, pTab, rSDev, rSDev.test.R, SDev, stats
  • bug in daFisher solved and new adapted predict function

Changes in robCompositions version 2.0.3

  • new function perturbation() and powering()
  • new function for inner product (iprod())
  • new funciton balances()
  • addLR, cenLR with optional different base in logrithm
  • isomLR with more possibilites for a normalizing constant
  • isomLR depricated, using now pivotCoord instead
  • isomLRinv depricated, using pivotCoordInv instead
  • orthbasis() now returns also the basis vectors
  • bug in aDist solved
  • aDist now much faster
  • new function center()
  • method symm (symmetric balances) in pivotCoord

Changes in robCompositions version 2.0.2

  • new function balZav()
  • new function daCoDa()
  • new function clustCoDa()
  • new function corCoDa()
  • aDist for single matrix
  • pcaCoDa() with external variables
  • new data set alcoholreg
  • new data set alcohol
  • new data set econom
  • new data set ageCatWorld
  • new data set election
  • new data set laborForce
  • new data set payments

Changes in robCompositions version 2.0.1

  • discriminant analysis (daFisher) for n-group case
  • discriminant analysis (daFisher) including predict
  • discriminant analysis (daFisher) including misclassification rates

Changes in robCompositions version 2.0.0

  • combined help for some S3methods
  • function robVariation is now called variation
  • new data sets

Changes in robCompositions version 1.9.1

  • now with roxygen2 documentation
  • minor modifications in impRZilr

Changes in robCompositions version 1.9.0

  • bug in robVariations solved

Changes in robCompositions version 1.8.0

  • critical bug in function impRZilr solved (did worked only correct for constant sum data)

Changes in robCompositions version 1.7.0

  • bug in function impRZilr solved
  • new bootstrap procedure for estimating the number of components within impRZilr
  • description in function impRZilr adapted

Changes in robCompositions version 1.6.4

  • deprecated functions alr, ilr, clr, invalr, invilr, invclr deleted
  • bugfix and enhancement of impRZilr.R
  • improvement of isomLR for high-dimensional data

Changes in robCompositions version 1.6.3

+ function impAll included.
+ robGUI excluded (is now put in the compositionsGUI package)

Changes in robCompositions version 1.6.2

+ alr, clr, ilr, invalr, invclr, invilr are now deprecated. The new functions are called
  addLR, cenLR, isomLR, addLRinv, cenLRinv, isomLRinv
+ new functions gm, orthbasis, missPatterns and zeroPatterns
+ return instead of invisible return for all log-ratio transformations

Changes in robCompositions version 1.5.0

+ variable names in expendiure data corrected
+ graphical user interface added    
+ vignette about an overview of the package added
+ alrEM() function now renamed in impRZalr() to be consistent with notation

Changes in robCompositions version 1.4.6

+ correct transformation of the detection limit in impRZilr when having not constant sum 1.

Changes in robCompositions version 1.4.5

+ Bug in alrEM fixed.

+ impRZilr included, but without documentation.

Changes in robCompositions version 1.4.4

+ Description for the Expenditures data changed. Wrong variable description fixed.

+ Wrong formula in robVariation method robust=FALSE fixed after an comment 
  from from Mark Engle (thanks!).

+ Improved code in 'CITATION' file.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


2.3.1 by Matthias Templ, 4 months ago

Browse source code at

Authors: Matthias Templ [aut, cre] , Karel Hron [aut] , Peter Filzmoser [aut] , Kamila Facevicova [ctb] , Petra Kynclova [ctb] , Jan Walach [ctb] , Veronika Pintar [ctb] , Jiajia Chen [ctb] , Dominika Miksova [ctb] , Bernhard Meindl [ctb] , Alessandra Menafoglio [ctb] , Alessia Di Blasi [ctb] , Federico Pavone [ctb] , Nikola Stefelova [ctb] , Gianluca Zeni [ctb]

Documentation:   PDF Manual  

Task views:

GPL (>= 2) license

Imports car, cvTools, e1071, fda, rrcov, cluster, fpc, GGally, ggfortify, kernlab, MASS, mclust, tidyr, robustbase, robustHD, splines, VIM, zCompositions, reshape2, Rcpp

Depends on ggplot2, pls, data.table

Suggests knitr, testthat

Linking to Rcpp, RcppEigen

Suggested by classmap.

See at CRAN