Article Rnews 2007
The ade4 package  II: Twotable and {K}table methods
The ade4 package  II: Twotable and Ktable methods
by Stéphane Dray, Anne B. Dufour and Daniel Chessel
S. Dray, A.B. Dufour, and D. Chessel. 2007. The ade4 package  II: Twotable and Ktable methods. R News 7(2):4752.
Introduction
Ecological illustration
Matching two tables
The Ktable class
Conclusion
1 Introduction
The ade4 package proposes a great variety of explanatory methods to analyse multivariate datasets.
As suggested by the acronym ade4 (Data Analysis functions to analyse Ecological and
Environmental data in the framework of Euclidean
Exploratory methods), the package is devoted to ecologists but it could be useful in many
other fields [e.g.,Goecke, 2005]. Methods available in the package are particular cases of the
duality diagram [Escoufier, 1987,Holmes, 2006,Dray and Dufour, 2007] and the implementation of the functions follows the
description of this unifying mathematical tool (class dudi).
The main functions of the package for onetable analysis methods have been presented in Chessel et al. [2004].
This new paper presents a short summary of twotable and Ktable methods available in the package.
2 Ecological illustration
In order to illustrate the methods, we used the dataset jv73 [Verneaux, 1973] which is available in the package. This dataset concerns 12 rivers. For each river, a number of sites have been sampled. The number of sites per river is not constant. jv73$poi is a data.frame and contains presence / absence data for 19 fish species (columns) in 92 sites (rows). jv73$fac.riv is a factor indicating the river corresponding to each site. jv73$morpho contains the measurements of six environmental variables (altitude (m), distance between the site and the source (km),
slope (per thousand), wetted cross section (m^{2}), average flow (m^{3}/s) and average speed (m/s)) for the same sites . Several ecological questions are related to these data:
 Are they groups of fish species living together (i.e. species communities)?
 Is there a relation between the composition of fish communities and the environmental variations?
 Does the composition of fish communities vary (or not) among rivers?
 Do the speciesenvironment relationships vary (or not) among rivers?
Multivariate analyses help to answer these different questions: onetable methods for the first question, twotable methods for the second one and Ktable methods for the last two ones.
3 Matching two tables
The main purpose of ecological data analysis is the matching of
two data tables: a sitesbyenvironmental variables table and a
sitesbyspecies table, to study the relationships between the composition of species
communities and their environment. The ade4 package contains the main variants of these methods
(procrustean rotation, coinertia analysis and principal component analyses with respect to instrumental variables).
The first approach is procrustean rotation [Gower, 1971],
introduced in ecology by [Digby and Kempton, 1987, p. 116].
data(jv73)
pca1 < dudi.pca(jv73$morpho, scannf = FALSE)
pca2 < dudi.pca(jv73$poi, scale = FALSE,
scannf = FALSE)
plot(procuste(pca1$tab, pca2$tab,
nf = 2))
Figure 1:
Plot of a Procrustes analysis: loadings for environmental variables and species,
eigenvalues screeplot, scores of sites for the two data sets, and projection of the
two sets of sites after rotation (arrows link environment site score to the species site score) [Dray et al., 2003a].
Two randomization procedures are available to test the association between two tables: PROTEST [Jackson, 1995]
and RV [Heo and Gabriel, 1998].
plot(procuste.randtest(pca1$tab,
pca2$tab), main = "PROTEST")
plot(RV.rtest(pca1$tab, pca2$tab),
main = "RV")
Figure 2: Plots of PROTEST and RV tests: histograms of simulated
values and observed value (vertical line).
Coinertia analysis [Dolédec and Chessel, 1994,Dray et al., 2003b] is a general approach that can be applied to any pair of
duality diagrams having the same row weights. This method is symmetric and seeks for a common structure between
two datasets. It extends psychometricians interbattery analysis [Tucker, 1958], canonical
analysis on qualitative variables [Cazes, 1980], and ecological profiles analysis [Montaña and GreigSmith, 1990,Mercier et al., 1992].
Coinertia analysis of the pair of triplets (X_{1},Q_{1},D) and (X_{2},Q_{2},D) leads to the triplet (X_{2}^{t}DX_{1},Q_{1},Q_{2}). Note that the two triplets must have the same row weights.
coa1 < dudi.coa(jv73$poi, scannf = FALSE)
pca3 < dudi.pca(jv73$morpho, row.w = coa1$lw,
scannf = F)
plot(coinertia(coa1, pca3, scannf = FALSE))
Figure 3: Plot of a coinertia analysis: projection of
the principal axes of the two tables (species and environment) on coinertia axes,
eigenvalues screeplot, canonical weights of species and environmental variables, and joint display of the sites.
For each coupling method, a generic plot function allows to represent the various elements required to interpret the results. However, the quality of graphs could vary according to the data set. It is consequently impossible to manage relevant graphical outputs for all cases. That is why these generic plot use graphical functions of ade4 which can be directly called by the user. A brief description of some of these functions is given in table 1.
Function  Objective 
s.arrow  cloud of points with vectors 
s.chull  cloud of points with groups by convex hulls 
s.class  cloud of points with groups by stars or ellipses 
s.corcircle  correlation circle 
s.distri  cloud of points with frequency distribution by stars and ellipses 
s.hist  cloud of points with two marginal histograms 
s.image  grid of grayscale rectangles with contour lines 
s.kde2d  cloud of points with kernel density estimation 
s.label  cloud of points with labels 
s.logo  cloud of points with pictures 
s.match  matching two clouds of points with vectors 
s.traject  cloud of points with trajectories 
s.value  cloud of points with numerical variable 
Table 1: Objectives of some graphical functions.
Another twotable matching strategy is principal component analyses with respect to instrumental variables (pcaiv, [Rao, 1964]). This approach consists in explaining a triplet (X_{2}, Q_{2}, D) by a table of independent variables X_{1} and leads to triplet
(P_{X1}X_{2}, Q_{2},D) where P_{X1}=X_{1}(X_{1}^{t}DX_{1})^{1}X_{1}^{t}D. This family
of methods are constrained ordinations, among which redundancy analysis [van den Wollenberg, 1977] and canonical
correspondence analysis [Ter Braak, 1986] are the
most frequently used in ecology. Note that canonical correspondence analysis can also be performed using the cca wrapper function which takes two tables as arguments. The example given below is then exactly equivalent to plot(cca(jv73$poi,jv73$morpho,scannf=FALSE)). While the cca function of ade4 is a particular case of pcaiv, the cca function of the package vegan is a more traditional implementation of the method which could be preferred by ecologists.
plot(pcaiv(coa1, jv73$morpho, scannf = FALSE))
Figure 4: Plot of a CCA seen as a particular case of PCAIV:
environmental variables loadings and correlations with CCA axes,
projection of principal axes on CCA axes, species scores, eigenvalues
screeplot, and joint display of the rows of the two tables (position
of the sites by averaging (points) and by regression (arrow tips)).
Orthogonal analysis (pcaivortho) allows to remove the effect of independent variables and corresponds to the triplet (P_{^X1}X_{2}, Q_{2},D) where P_{^X1}=I  P_{X1}. Betweenclass (between) and withinclass (within) analyses (see Chessel et al. [2004] for details) are particular cases of PCAIV and orthogonal PCAIV when there is only one categorical variable (i.e. factor) in X_{1}. Withinclass analyses allow to take into account a partition of individuals into groups and focus on structures which are common to all groups. It can be seen as a first step to Ktable methods.
wit1 < within(coa1, fac = jv73$fac.riv,
scannf = FALSE)
plot(wit1)
Figure 5: Plot of a withinclass analysis: species loadings, species scores, eigenvalues
screeplot, projection of principal axes on withinclass axes, sites scores (common centring), projections of sites and groups (i.e. rivers in this example) on withinclass axes.
4 The Ktable class
Class ktab corresponds to collections of more than two duality diagrams, which internal structures are to be compared.
Three formats of these collections can be considered:
 (X_{1},Q_{1},D),
(X_{2},Q_{2},D),..., (X_{K},Q_{K},D)
 (X_{1},Q,D_{1}), (X_{2},Q,D_{2}),..., (X_{K},Q,D_{K}) stored in the form of (X_{1}^{t},D_{1},Q), (X_{2}^{t},D_{2},Q),..., (X_{K}^{t},D_{K},Q)
 (X_{1},Q,D), (X_{2},Q,D),..., (X_{K},Q,D) which can also be stored in the form of (X_{1}^{t},D,Q), (X_{2}^{t},D,Q),..., (X_{K}^{t},D,Q)
Each statistical triplet corresponds to a separate analysis (e.g., principal component analysis, correspondence analysis ...). The common dimension of the K statistical triplets are the rows of tables which can represent individuals (samples, statistical units) or variables. Utilities for building and manipulating ktab objects are available. Ktable can be constructed from a list of tables (ktab.list.df), a list of dudi objects (ktab.list.dudi), a withinclass analysis (ktab.within) or by splitting a table (ktab.data.frame). Generic functions to transpose (t.ktab), combine (c.ktab) or extract elements ([.ktab) are also available. The sepan function can be used to compute automatically the K separate analyses.
kt1 < ktab.within(wit1)
sep1 < sepan(kt1)
kplot.sepan.coa(sep1, permute.row.col = TRUE)
Figure 6:
Kplot of 12 separate correspondence analyses (same species, different sites).
When the ktab object is built, various statistical methods can be used to analyse it. The foucart function can be used to analyse K tables of positive number having the same rows
and the same columns and that can be analysed by a CA [Foucart, 1984,Pavoine et al., 2007].
Partial triadic analysis [Tucker, 1966] is a first step toward
three modes principal component analysis [Kroonenberg, 1989] and can be
computed with the pta function. It must be used on K
triplets having the same row and column weights. The pta function can be used to perform the STATICO method [Simier et al., 1999,Thioulouse et al., 2004]. This allows to analyse a pair of ktab objects which have been combined by the ktab.match2ktabs function.
Multiple factor analysis (mfa, [Escofier and Pagès, 1994]), multiple coinertia analysis (mcoa, [Chessel and Hanafi, 1996]) and the STATIS
method (statis, [Lavit et al., 1994]) can be used to compare K triplets having the
same row weights. The STATIS method can also
be used to compare K triplets having the same column weights, which is a first step toward Common PCA [Flury, 1988].
sta1 < statis(kt1, scannf = F)
plot(sta1)
Figure 7:
Plot of STATIS analysis: interstructure, typological value of each table, compromise and projection of principal axes of separate analyses onto STATIS axes.
The kplot generic function is associated to the foucart, mcoa, mca, pta, sepan, sepan.coa and
statis methods, giving adapted collections of graphics.
kplot(sta1, traj = TRUE, arrow = FALSE,
unique = TRUE, clab = 0)
Figure 8:
Kplot of the projection of the sites of each table on the principal axes of the compromise of STATIS analysis.
5 Conclusion
The ade4 package provides many methods to analyse multivariate ecological data sets.
This diversity of tools is a methodological answer to the great variety of questions and data
structures associated to biological questions. Specific methods dedicated to the analysis of biodiversity,
spatial, genetic or phylogenetic data are also available in the package. The adehabitat brotherpackage
contains tools to analyse habitat selection by animals while the ade4TkGUI package provides a graphical
interface to ade4. More ressources can be found on the ade4 website (http://pbil.univlyon1.fr/ADE4/).
Bibliography
 [Cazes 1980]

P. Cazes.
L'analyse de certains tableaux rectangulaires décomposés en
blocs : généralisation des propriétés rencontrées dans
l'étude des correspondances multiples. I. Définitions et
applications à l'analyse canonique des variables qualitatives.
Les Cahiers de l'Analyse des Données, 5:
145161, 1980.
 [Chessel and Hanafi 1996]

D. Chessel and M. Hanafi.
Analyse de la coinertie de K nuages de points.
Revue de Statistique Appliquée, 44 (2):
3560, 1996.
 [Chessel et al. 2004]

D. Chessel, A.B. Dufour, and J. Thioulouse.
The ade4 packageI Onetable methods.
R News, 4: 510, 2004.
 [Digby and Kempton 1987]

P. G. N. Digby and R. A. . Kempton.
Multivariate Analysis of Ecological Communities.
Chapman and Hall, Population and Community Biology Series, London,
1987.
 [Dolédec and Chessel 1994]

S. Dolédec and D. Chessel.
Coinertia analysis: an alternative method for studying
speciesenvironment relationships.
Freshwater Biology, 31: 277294, 1994.
 [Dray and Dufour 2007]

S. Dray and A. Dufour.
The ade4 package: implementing the duality diagram for ecologists.
Journal of Statistical Software, 22 (4):
120, 2007.
 [Dray et al. 2003a]

S. Dray, D. Chessel, and J. Thioulouse.
Procrustean coinertia analysis for the linking of multivariate
datasets.
Ecoscience, 10: 110119, 2003a.
 [Dray et al. 2003b]

S. Dray, D. Chessel, and J. Thioulouse.
Coinertia analysis and the linking of ecological tables.
Ecology, 84 (11): 30783089,
2003b.
 [Escofier and Pagès 1994]

B. Escofier and J. Pagès.
Multiple factor analysis (AFMULT package).
Computational Statistics and Data Analysis, 18:
121140, 1994.
 [Escoufier 1987]

Y. Escoufier.
The duality diagram : a means of better practical applications.
In P. Legendre and L. Legendre, editors, Development in
numerical ecology, pages 139156. NATO advanced Institute , Serie G
.Springer Verlag, Berlin, 1987.
 [Flury 1988]

B. Flury.
Common Principal Components and Related Multivariate. models.
Wiley and Sons, NewYork, 1988.
 [Foucart 1984]

T. Foucart.
Analyse factorielle de tableaux multiples.
Masson, Paris, 1984.
 [Goecke 2005]

R. Goecke.
3D lip tracking and coinertia analysis for improved robustness of
audiovideo automatic speech recognition.
In Proceedings of the AuditoryVisual Speech Processing
Workshop AVSP 2005, pages 109114, 2005.
 [Gower 1971]

J. Gower.
Statistical methods of comparing different multivariate analyses of
the same data.
In F. Hodson, D. Kendall, and P. Tautu, editors, Mathematics in
the archaeological and historical sciences, pages 138149. University
Press, Edinburgh, 1971.
 [Heo and Gabriel 1998]

M. Heo and K. Gabriel.
A permutation test of association between configurations by means of
the RV coefficient.
Communications in Statistics  Simulation and Computation,
27: 843856, 1998.
 [Holmes 2006]

S. Holmes.
Multivariate analysis: The French way.
In N. D. and S. T., editors, Festschrift for David Freedman.
IMS, Beachwood, OH, 2006.
 [Jackson 1995]

D. Jackson.
PROTEST: a PROcustean randomization TEST of community
environment concordance.
Ecosciences, 2: 297303, 1995.
 [Kroonenberg 1989]

P. Kroonenberg.
The analysis of multiple tables in factorial ecology. iii threemode
principal component analysis:änalyse triadique complète".
Acta OEcologica, OEcologia Generalis, 10: 245256,
1989.
 [Lavit et al. 1994]

C. Lavit, Y. Escoufier, R. Sabatier, and P. Traissac.
The ACT (STATIS method).
Computational Statistics and Data Analysis, 18:
97119, 1994.
 [Mercier et al. 1992]

P. Mercier, D. Chessel, and S. Dolédec.
Complete correspondence analysis of an ecological profile data table:
a central ordination method.
Acta OEcologica, 13: 2544, 1992.
 [Montaña and GreigSmith 1990]

C. Montaña and P. GreigSmith.
Correspondence analysis of species by environmental variable
matrices.
Journal of Vegetation Science, 1: 453460, 1990.
 [Pavoine et al. 2007]

S. Pavoine, J. Blondel, M. Baguette, and D. Chessel.
A new technique for ordering asymmetrical threedimensional data sets
in ecology.
Ecology, 88: 512523, 2007.
 [Rao 1964]

C. Rao.
The use and interpretation of principal component analysis in applied
research.
Sankhya A, 26: 329359, 1964.
 [Simier et al. 1999]

M. Simier, L. Blanc, F. Pellegrin, and D. Nandris.
Approche simultanée de K couples de tableaux : application
à l'étude des relations pathologie végétaleenvironment.
Revue de Statistique Appliquée, 47: 3146, 1999.
 [Ter Braak 1986]

C. Ter Braak.
Canonical correspondence analysis : a new eigenvector technique for
multivariate direct gradient analysis.
Ecology, 67: 11671179, 1986.
 [Thioulouse et al. 2004]

J. Thioulouse, M. Simier, and D. Chessel.
Simultaneous analysis of a sequence of pairs of ecological tables
with the STATICO method.
Ecology, 85: 272283, 2004.
 [Tucker 1958]

L. . Tucker.
An interbattery method of factor analysis.
Psychometrika, 23: 111136, 1958.
 [Tucker 1966]

L. Tucker.
Some mathemetical notes on threemode factor analysis.
Psychometrika, 31: 279311, 1966.
 [van den Wollenberg 1977]

A. van den Wollenberg.
Redundancy analysis, an alternative for canonical analysis.
Psychometrika, 42 (2): 207219, 1977.
 [Verneaux 1973]

J. Verneaux.
Cours d'eau de FrancheComté (Massif du Jura).
Recherches écologiques sur le réseau hydrographique du Doubs.
Essai de biotypologie.
Thèse de doctorat, Université de Besançon, Besançon,
1973.
File translated from
T_{E}X
by
T_{T}H,
version 3.78. On 23 Oct 2007, 18:32.
