2005 Compositionaldata Scotland
2005 Compositionaldata Scotland
July 2005
This pdf file is a text version of an online course, which can be found at:
[Link]
1
Aims of this module
• Describe the common features of compositional data, and outline why such
datasets cannot be analysed using standard techniques
• Introduce the log-ratio approach, explaining the advantages (and limitations)
of this approach
• Discuss issues of statistical modelling & inference, and outline currently
available software for implementing these methods
• Introduce a conditionally autoregressive model for the analysis of
compositional data on regular grids
• Present case studies relevant to the analysis of ecological datasets using
compositional methods
'Composition deals with the bits and pieces that make up things' (Wikipedia
definition).
'Composition: the constitution of something made up from different elements' (Oxford
dictionary definition)
Geologists, for example, are often interested in describing and understanding the
mineral composition of rock samples. It may well be scientifically interesting to know
that 70% of a particular rock sample consists of quartz (compositional data), but it
would be of no conceivable interest to know that a sample of unknown size contained
5g of quartz (data on absolute frequencies). Within biology, dietary data are often
compositional - for example, seabird diet studies typically record the relative
proportions of two or more different prey species found within the regurgitated
stomach contents of individual birds. Again, scientists are really only interested in
relative frequencies, because the absolute amount of regurgitated material depends
upon a whole lot of factors which are completely unrelated to the diet of the seabird -
e.g. the size of the bird, whether the bird regurgitates all of the stomach contents,
whether the experimenter collects all of this material etc. etc. etc...
2
1.1 Examples
Here, we describe a number of example datasets that we will use within this module.
The raw data and further details of these data sets have been made available at:
[Link] .
Compositional data are subject to a unit sum constraint - i.e. because they are
proportions they must sum to one. This sum constraint in turn imposes some
unpleasant constraints upon the variance-covariance matrix of X, and so, at a stroke,
invalidates most standard statistical approaches - including techniques based on
regression and multivariate analysis - which rely on an assumption of multivariate
normality. It is important to appreciate that correlations between proportions are
difficult (and, for large D, effectively impossible) to interpret in any meaningful way,
not least because uncorrelated proportions are not necessarily independent.
The approach which we will outline in this course involves breaking the sum
constraint - i.e. using a transformation of the data to remove the constraint, and then
applying standard statistical techniques to the transformed data. The approach is
analogous to the modelling of binary data using a generalised linear model with
logistic link function - i.e. logistic regression (McCullagh & Nelder, 1989) - and will
actually turn out to be quite closely related to that approach.
3
1.3 Some basic principles
Scale invariance: statistical inferences about compositional data should not depend
upon the scale used. For example, we should obtain exactly the same results if we
analyse percentages (of 100) as we would if we analysed proportions (of 1).
Permutation invariance: statistical inferences should not depend upon the ordering (or
labelling) of the components. It should not matter, for example, which component we
choose to be the "first" and which component we choose to be the "last".
When building a statistical model, one needs to define a sample space: a convenient
reference space within which experimental outcomes can be unambiguously recorded.
It is generally - although not quite universally - agreed that the appropriate sample
space for compositional data is the standard simplex (also called the "unit simplex").
where D = d + 1.
Note from this definition that a composition of D parts actually lies within a (D - 1)-
dimensional set. This make sense - if we know the proportions of D - 1 components,
then (since the proportions must sum to one) we will also know the proportion
associated with the final component. In particular, in the case of just two components
(D = 2) it is obvious that if we know the proportion associated with one component
then we also know the proportion associated with the other component, so we really
only have information on one dimension (i.e. d = 1).
4
1.5 Graphical representations
Ternary diagrams
5
Spiderplots
The key to the spokes is: 1=Fair, 2=Red, 3=Medium, 4=Dark, 5=Jet black.
We see that fair, medium & dark hair are fairly common in all of the counties, whilst
jet black and red are quite rare. The proportions show a very low level of variability
between counties (indicated by the fact that the red polygons are all quite close to
each other), suggesting that hair colour does not strongly depend upon location within
Scotland.
6
1.6 Limits to interpretability
Compositional data only contain partial information - they provide information only
about the relative values of components - so there are fundamental limitations to what
we can learn through the analysis of a compositional dataset.
As a simple example, suppose that John keeps bananas, oranges & apples in his fruit
basket. John sometimes eats some of the fruit in the baset, and sometimes he buys
some more. All we know, however, is that at the start of a particular week he has 1/3
apples, 1/3 bananas and 1/3 oranges in the basket, but that by the end of the week has
has 1/6 apples, 1/6 bananas and 2/3 oranges.
What can we conclude from this information ? Well, actually very little -
• we cannot conclude that John has bought any fruit, or that John has eaten any
fruit;
• we cannot conclude that the overall amount of fruit in the basket has gone up,
gone down, or stayed the same;
• and we cannot conclude that the number of oranges has gone up, gone down,
or stayed the same.
We can only conclude that the proportion of oranges is higher at the end of the week
than at the start, and that the proportions of apples and bananas are correspondingly
lower.
2 Log-ratios of proportions
We have seen that compositional data are most definitely non-normally distributed -
since they must always lie between zero and one, and they must sum to one - and that
analyses of compositional data based on an assumption of normality can often lead to
wildly missleading inferences. Fortunately, however, we can usually transform
compositional data onto a scale where they are normal - and, in addition, we can do
this using a extraordinarily simple transformation.
We will assume henceforth that the data contain no zero proportions, so that Xj > 0 for
all j = 1,...,D. We will to the thorny issue of zero proportions at a much later stage.
7
2.1 A simple case: two components
Begin by considering the simple situation where we have just two components, so that
D = 2. In his seminal book, Aitchison (1986) suggests that the appropriate model for
X1 and X2 will generally be to assume that the log-ratio, log(X2 / X1), has a normal
distribution.
Within statistics, transformations are usually used to remove constraints. For example,
the log transformation is used to convert a variable which must be positive into a
variable which can take any real (positive or negative) value. A simple graph:
shows that, even though X1 must lie between zero and one, the log-ratio
can take any real value. We therefore see that the log-ratio transformation is effective
in removing the constraints on X.
8
Why should the log-ratio be normally distributed ?
We have shown that the log-ratio log(X2 / X1) can take any real value. This is an
essential prerequisite for normality, but it certainly does not demonstrate that the log-
ratio is normally distributed. Aitchison shows that the standard mathematical
arguments for assuming normality in statistics - such as the central limit theorem -
also apply to the log-ratios of compositional data. We must still, however, check the
validity of the normality assumption for the dataset at hand.
9
logratio <- log(proportion / (1 - proportion))
## ...and plot another histogram:
hist(logratio,xlab="log-ratio",main="log(propn. female / propn. male)")
There are two possible log-ratios which we could have modelled, so what would have
happened if we had used the "other" log-ratio, log(X1 / X2), instead ? Well, using
elementary properties of logs we can see that
So the two log-ratios will always have identical values, but they will have different
sign. We therefore only need to model one of the two log-ratios, and it does not matter
which one...
10
It is worth noting that log-ratios crop up elsewhere in statistics, particularily in the
field of logistic regression.
In logistic regression we have a binary (0/1) outcome which we assume to have arisen
from a Bernoulli distribution, and we wish to model the probability p of a positive
outcome (1) as a function of explanatory variables. We transform the probability onto
the real line using the logit link function, log[p / (1 - p)], which is simply the log-ratio
of p to (1 - p).
We can see that logistic regression has a lot in common with our model for
compositional data when D = 2. The key difference is that for compositional data we
actually observe the proportion p, whereas in logistic regression this proportion is an
unobserved quantity which represents the probability associated with an observed
binary event.
We can adopt a similar approach when the number of components D is greater than
two.
follow a multivariate normal distribution with mean vector &mu and covariance
matrix &Sigma .
Note that this model contains a total of d(d+1) parameters: there are d means, d
variances, and d(d-1) correlations.
Permutation invariance
It can shown that the same statistical inferences will result, regardless of which of the
variables is taken as the denominator in the log-ratios - i.e. that an approach based on
analysing log-ratios is "permutation invariant" (Aitchison, 1986; Section 5.5). The
choice of denominator is, consequently, somewhat arbitrary: we have taken the
denominator to be X1 in our definiton, but it could equally well have been XD, or
indeed any of the other variables. Permutation invariance is an attractive property of
the log-ratio approach.
11
Alternative transformations
Aitchison also proposes some alternative (but closely related) transformations, which
are more useful for dealing with certain non-standard forms of compositional data.
Backtransformation
Making the assumption that the log-ratios log(X2 / X1),...,log(XD / X1) have a
multivariate normal distribution amounts to an assumption that the original variables
X1,...,XD have a particular distribution - this distribution is usually called the
multivariate log-ratio normal distribution. Fitting a multivariate log-ratio normal
distribution to X1,...,XD is equivalent to fitting a multivariate normal distribution to the
log-ratios log(X2 / X1),...,log(XD / X1).
## We take log-ratios...
logratio <- cbind(log(skye$F / skye$A),log(skye$M / skye$A))
## ...and draw a scatterplot:
plot(logratio[,1],logratio[,2],pch="+",xlab="log(F/A)",ylab="log(M/A)")
12
## We note that the log-ratios of M to A and F to A are highly positively
correlated:
Once we have transformed onto the log-ratio scale, then we can estimate the mean
and variance of the (multivariate) normal distribution using the full range of standard
methods available for statistical inference - such as maximum likelihood, least
squares, or Bayesian methods. We do not discuss the relative practical &
philosophical merits of the various approaches here, but do note that Bayesian
inference via Markov Chain Monte Carlo is probably the most feasible option for
dealing with high dimensional problems (when D is large).
13
2.5 Independence
What does the concept of statistical independence mean within the context of
compositional data ? Standard ideas of independence are clearly irrelevant, because
compositional data are subject to the constraint that they must sum to one. It turns out
that a number of different concepts of "compositional independence" are possible,
with different concepts being useful in different contexts. We restrict our attention
here only to the most widely used concept of independence for compositional data,
that of complete subcompositional independence.
3 Compositional regression
Some notation:
for each of i=1,...,N individuals or replicates. Assume that we also know the values of
M covariates z1i ..., zMi for each individual/replicate.
14
3.1 A simple case
We begin with the simple case where the response variable has just two components
(i.e. D = 2). The statistical strategy here involves:
- fitting a standard regression model to this log-ratio transformed data; and finally
We will skip over the issues involved in selecting an appropriate regression model -
since these are generic and widely discussed elsewhere - and focus on the mechanics
of transformation and backtransformation.
A linear model
The most common approach will be to assume that the log-ratios are normally
distributed,
where the mean µ i is related to the covariates via a linear model of the form
The regression coefficients a1..., aM are unknown parameters of the model, and,
together with the variance σ 2 and intercept a0, need to be estimated.
Through a backtransformation onto the original scale, we can use the regression
model to obtain fitted values for Xi1,
15
## We illustrate the idea of backtransformation using a simple example.
## Assume that a = 0 and b = 1 in the above model, so that a plot of Z against the log-
ratio is linear:
plot(-10:10,-10:10,type='l',xlab="Z",ylab="log(X2 / X1)") :
16
A worked example (using R): the Gaelic language
17
Call:
lm(formula = logratio ~ gaelic$Age)
Residuals:
Min 1Q Median 3Q Max
-3.1075 -1.5176 0.2992 1.6118 3.0036
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.26323 3.77582 0.864 0.395
gaelic$Age -0.08969 0.08771 -1.023 0.316
## The p-value associated with the slope parameter is far from being statistically
significant,
## so we certainly cannot reject the null hypothesis of no relationship between age
and proportion.
Call:
lm(formula = logratio ~ gaelic$Age + gaelic$Age2)
Residuals:
Min 1Q Median 3Q Max
-3.1092 -1.5170 0.2975 1.6108 3.0033
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.9998432 28.7625482 0.104 0.918
gaelic$Age -0.0772554 1.3490311 -0.057 0.955
gaelic$Age2 -0.0001457 0.0157716 -0.009 0.993
## ...but we find that neither the linear or quadratic term is statistically significant.
The linear model of the last slide can be extended to allow for more than two
components (i.e. D > 2). Specifically, we assume that the log-ratios have a
multivariate normal distribution,
18
whose mean vector &mui is related to the covariates through the linear model
Note that the ak now refer to vectors of regression coefficients; the model can also be
re-expressed without the use of vector notation, through the formula:
## We can plot the log-ratios against depth, and against each other:
par(mfrow=c(2,2))
plot(arctic$Depth, logratio$SiltSand, pch="+", xlab="depth",ylab="log(silt/sand)")
plot(arctic$Depth, logratio$ClaySand, pch="+", xlab="depth",ylab="log(clay/sand)")
plot(logratio$SiltSand, logratio$ClaySand, pch="+",
xlab="log(silt/sand)",ylab="log(clay/sand)")
19
## The scatterplots suggest that the ratios of silt to sand and clay to sand both increase
with water depth;
## the plots also indicate a strong positive correlation between the two log-ratios.
3.3 Interpretation
Having estimated the parameters of the multivariate normal distribution on the log-
ratio scale, we can then backtransform onto the original (compositional) scale. The
backtransformed parameter estimates do not necessarily have any obvious
interpretation, however.
One important exception is the intercept parameter, a0; Billheimer et al. (2001) note
that we can backtransform an estimate of the intercept parameter using
20
to obtain an estimate for the multivariate median of the composition.
We can also backtransform fitted values from the model onto the original scale, using
In this section we outline a modern statistical approach for dealing with spatially
autocorrelated compositional data, and illustrate this approach using gridded data on
the spatial distribution of a specific biological trait (flower colour). Grid-based data
frequently arise in the context of species atlases, so the methods which we present
have broad applicability within ecology.
21
Some notation:
for each of i=1,...,N cells on a regular spatial grid. Assume that we also know the
values of M covariates z1i ..., zMi for each grid cell i.
to describe the effect of the spatial covariates z1i ..., zMi upon the mean vector &mui.
Comparing against our earlier non-spatial model, we can see that the new elements
within the CAR model are the multivariate random effects,
which are assumed to be spatial correlated and Gaussian (multivariate normal). Define
the neighborhood &delta(i) of grid cell i to be the set of grid cells which are directly
adjacent or diagonal to grid cell i, and let n(i) denote the number of grid cells in
neighbourhood &delta(i). The spatial random effects are assumed to have conditional
distributions of the form
22
where Ω is a d x d dimensional variance-covariance matrix. Note that the conditional
means are simply the mean random effects within the neighbourhood &delta(i) of grid
cell i, and that the conditional covariance matrix is inversely proportional to the
number of grid cells n(i) contained in this neighbourhood. The random effects for
each component are constrained to sum to zero over space (Besag & Kooperberg,
1995), so that
We use a simulated dataset on the proportion of flowers having each of three different
colours (red, blue & yellow) for cells on the 10km-by-10km Ordnance Survey grid of
the United Kingdom. Proportions of flower colours are simulated in such a way that
spatial variations in the proportions are related to two (also hypothetical) variables,
which we call the biodiversity index and the limestone index. The biodiversity indices
are spatially independent, but the limestone indices exhibit strong spatial
autocorrelation - i.e. limestone indices for grid cells which are close together will tend
to be similar. The raw data, and the methods used to gerenrate the data are available
as an appendix.
23
This map illustrates the spatial distribution of the biodiversity index,
whilst this one show the spatial distribution of the limestone index:
24
4.3 Model fitting
We let
and model the proportions of flower colours using the CAR model introduced above.
Note that
We will assume (pretend) that we have no knowledge of the limestone index, and will
try to relate the proportions of different flower colours solely to the biodiversity
index. We fit a linear regression model of the form:
We estimate the parameters of the model within a Bayesian framework (see e.g.
Gelman et al., 1995). Within the Bayesian context parameters are treated as random
variables, and all inferences about the parameters are based on the posterior
distribution. The posterior distribution is obtained by using Bayes' theorem to
combine prior knowledge about the parameters together with knowledge about the
parameters gained from the data.
25
If f( θ ) denotes the prior distribution for the parameters &theta of a statistical model,
and if f(X| θ ) denotes the likelihood of data X within this model, then Bayes' theorem
states that
We used the GeoBUGS module (Thomas et al. 2004) of the WinBUGS package
(Spiegelhalter et al. 1999; Link et al., 2002) to fit the multivariate CAR model using
Markov chain Monte Carlo (McMC) techniques. WinBUGS/GeoBUGS provides an
efficient and user friendly environment for fitting a wide range of sophisticated
statistical models, many of which would be prohibitively difficult and/or expensive
(in time and labour) to fit in any other way. The WinBUGS code which we have used
is available here.
We must specify prior distributions for the parameters of the spatial model. We
choose to use uninformative priors (also called vague priors) for all of the parameters,
since we do not wish to make strong prior assumptions about the values of the
parameters.
We take the prior for the intercept term to be a location invariant uniform distribution,
so that
We take priors for the regression coefficients to be normally distributed with zero
mean and a large variance, so that
Finally, we take priors for the precision matrices (i.e. inverted variance-covariance
matrices) within our model to be Wishart distributions,
26
The parameter a determines the precision of the spatial random effect within the CAR
model, and it is important to test the sensitivity of the final results to the choice of
prior value for this parameter. We take a = 0.1 in our analysis, but obtained similar
results with the alternative choices a = 0.01 and a = 0.005.
Multiple Markov chains were run starting from different points, and the chains were
assumed to have converged when the 2.5%, 50% and 97.5% quantiles of the posterior
distributions obtained using the combined chains were sufficiently similar to those
obtained from the individual chains. We further checked convergence of the Markov
chains using visual inspection of the series of parameter estimates, autocorrelations of
these series, and the Brooks-Gelman-Rubin statistic (Brooks & Gelman, 1998).
We ran our Markov chains for 200000 iterations, discarded the first 20000 draws as
burn-in, and used only every 1 in every 10 iterations in order to overcome the effects
of autocorrelation. We based our inferences on the remaining 18000 draws from the
the posterior distribution.
We fit the Bayesian CAR model to the data using GeoBugs. The code for the
WinBUGS model is given below.
The posterior means and posterior standard deviations for the regression parameters
are:
The following ternary plot depicts the observed log-ratios (points), the fitted median
composition (obtained by back-transforming the posterior means of a 10 and a 02 ), and
the fitted regression line of the composition, as predicted by the observed gradient in
species-richness :
27
The prior distributions (red) and posterior distributions (black) for the elements of the
variance-covariance matrix of spatial random effects, Ω , are shown in the next set of
graphs. The posterior means for the variances Ω11 and Ω 22 are small, indicating
substantial levels of spatial autocorrelation in the model residuals. This residual
spatial autocorrelation results from the fact that the limestone index is not included as
a covariate within our model.
28
Spatial patterns in the posterior means of the spatial random effects closely
resemble the spatial pattern of the omitted "limestone index" covariate z2i. The
following map depicts the spatial distribution of , with a similar pattern for
The inclusion of the spatial random effects greatly decreased the residual deviance of
the model, indicating a substantial improvement in model performance over the non-
spatial version of the model.
29
5 Problematic compositional data
Statistical methods for dealing with compositional data using multivariate normal
models for log-ratios are well-established, and are motivated by sound theoretical
principles. This does not mean, however, that the techniques are suitable for analysing
absolutely *any* compositional dataset which we may encounter. In this section we
introduce some particularily "messy" datasets, explain why log-ratio normal models
are inappropriate for analysing these data, and - where appropriate - suggest some
alternative analyses.
the number of parameters in the model, d(d+3), will often be almost as large as - or
potentially even larger than - the number of replicates n, leading to overfitting; and
some of the components are likely to contain zero proportions, preventing us from
calculating log-ratios (see below).
The best solution will often - although not always - be to aggregate the data into a
smaller number of compositions, and then to fit an LR-normal model to this "reduced"
dataset. For example, we may group commodities together into a small number of
broad classes (food, toiletries, electrical goods etc.). Note that we are inevitably going
to lose a lot of information by doing this, so this approach will only be appropriate if
we can aggregate components together in some sensible and uncontroversial way.
## We use a dataset on the proportion of time that I spend in the office and elsewhere:
These data describe my daily activities during my first 6 months at BioSS. For each of
six blocks of four working weeks (20 working days), the data show the number of
days in which I was: at work in my office, away at a conference/meeting, away due to
a public holiday (e.g. Christmas), away on annual leave, or away on sick leave.
30
## The data record days spent in five different ways by a statistician (me) during six
blocks of four weeks:
## at the office, at conferences/meetings, on public holidays, on annual leave, or away
sick.
## They contain a number of zero proportions (e.g. because some four week blocks do
not contain any public holidays).
## We could aggregate the data into just two constituents ("at the office" and "away"):
leave_aggregated <- [Link](Office = leave$Office,
Away = leave$Conferences + leave$Public_holiday + leave$Annual_holiday +
leave$Sick):
Office Away
1 0.70 0.30
2 0.80 0.20
3 0.80 0.20
4 0.65 0.35
5 0.75 0.25
6 0.85 0.15
## This certainly gets rid of the zero proportions, but in simplifying things we also get
rid of possibly interesting information...
Many compositional datasets contain some zero proportions - i.e. for some of the
observations, one or more of the components is entirely absent. We cannot take the
logarithm of zero, so compositional data which contain zero proportions cannot be
dealt with using log-ratios. Statistical methods for dealing with zero proportions are
still under development, and no truly generic techniques for dealing with this problem
have yet been put forward.
31
zeroes") then things are less straightforward. The hierarchical modelling approach
proposed by Aitchison & Kay (2003) appears promising, but to date there have been
no substantial applications of this methodology.
These data quantify the extent to which nurses in a particular paediatic hospital used
gloves when performing routine medical activities. There are a total of 63 records,
corresponding to data for 23 individual nurses. The data record the number of
procedures undertaken by nurses during the period of observation (the "Obs" column),
and the number of these procedures for which gloves were worn (the "Gloves"
column). Data were collected prior to an short educational programme designed to
encourage glove use, and were subsequently collected one, two and five months after
the completion of this programme (the "Period" column denote the time point: 1 =
before programme, 2 = one month after, 3 = two months after, 4 = five months after).
Note, however, that not all of the nurses were monitored at all four time points. The
number of years experience for each nyse is also recorded (the "Experience" column).
The data are due to Friedland et al. (1992), and are available through the DASL
website ([Link]
The data record whether or not nurses in an emergency department wear gloves when
undertaking
medical procedures.
## ...and then working out the proportion of nurses that do and do not wear gloves:
proportion <- [Link](gloves = nurses$Gloves / nurses$Obs, nogloves =
(nurses$Obs - nurses$Gloves) / nurses$Obs)
32
## We see that the majority of proportions are either zero or one.
## The zero values in this example are essential zeroes: some nurses never wear
gloves, whilst some nurses always wear gloves.
## Data were collected before, and at three timepoints after, the nurses attended an
educational programme.
## The variable 'Period' identifies the timepoint (1 = before training, 2 = one month
after, 3 = two months after, 4 = five months after).
## There is interest is in understanding whether the training course has increased the
proportion of nurses that wear gloves.
## We can plot seperate histograms for data at each of the four timepoints:
par(mfrow=c(2,2))
hist(proportion$gloves[nurses$Period ==
1],breaks=seq(0,1,0.01),xlab="proportion",main="Before")
hist(proportion$gloves[nurses$Period ==
2],breaks=seq(0,1,0.01),xlab="proportion",main="1 month after")
hist(proportion$gloves[nurses$Period ==
3],breaks=seq(0,1,0.01),xlab="proportion",main="2 months after")
hist(proportion$gloves[nurses$Period ==
4],breaks=seq(0,1,0.01),xlab="proportion",main="5 months after")
33
## We see that prior to the training course, a large proportion of the nurses never wore
gloves.
## One to two months after the training course, most of the nurses wear gloves for
every procedure.
## Five months after the training course levels of glove use have fallen substantially -
## but are still higher than they were before the training course.
## This exploratory analysis gives us some interesting insights about the possible
effects of the educational programme.
## In order to gain solid evidence for any effect, however, we would need to analyse
these data using a formal statistical model.
34
5.3 Non-normality
The log-ratios of X will not always be well described by a multivariate normal model,
so it is important to verify that the assumption of normality is indeed a reasonable
one. The good news is that, once we have transformed our compositional data onto
the log-ratio scale, then we can use standard statistical tools to investigate whether the
data are normal.
If the diagnostic tests do find evidence of non-normality, then this suggests that the
normal model is not reasonable, so we must choose an alternative model for our data.
Choosing an appropriate model for compositional data is unlikely to be
straightforward, and at this point it may be sensible to seek the advice of a statistician.
Aitchison (1986, Ch.13) proposes some powerful generalisations of the LR-normal
distribution, and suggested that these are likely to be useful for dealing with non-
normal data.
What if our diagnostic tests do not find any evidence for non-normality ? In this case
we still cannot conclude that the data are normally distributed, but we can now
conclude that the data at least appear to be *consistent* with an assumption of
normality. We would then - usually - go ahead and fit an LR-normal model to the
data, always bearing in mind that the outcomes from our analyses will be dependent
upon the validity of the normality assumption.
## We use a small simulated dataset (the "bimodal" dataset, which is described here)
## to demonstrate one way in which the normality assumption may fail.
35
## ...which shows (pretty clear) evidence of bimodality
36
## ...and formally, using a Shapiro test:
[Link](logratio)
data: logratio
## The QQ plot shows serious discrepancies between the data and the fitted (normal)
model,
## whilst the Shapiro test conclusively rejects the null hypothesis of normality (with a
p-value of less than 0.001)
Most experts accept that analyses of compositional data should usually be based on
fitting a normal model to log-ratios, unless there are specific problems in adopting
such an approach (e.g. there are zero proportions, or the log-ratios exhibit non-
normality). A group of skeptical mathematical geologists have, however, argued that
the whole approach of fitting a statistical model to log-ratios of the proportions is
fundamentally misguided (e.g. Philip & Watson, 1988; Philip & Watson, 1989). They
advocate an alternative approach, based upon modelling the angles between
compositions using the geometry of the sphere rather than that of the simplex.
6 Additional resources
6.1 Software
Statistical methods for compositional data are not usually included within standard
statistical software packages, possibly explaining why these techniques are not more
widely used. Most of the methods are comparatively straightforward to code up from
scratch, however, and a number of add-ons to existing packages are also available.
R / Splus
37
• the ternaryplot function in the vcd library, for visualising data with three
components;
• the qqnorm, qqline and [Link] functions in the stats library, for testing
normality;
• the rmvnorm function in the mvtnorm library, for simulating from a
multivariate normal;
• the mvnormtest library, for testing multivariate normality.
The full range of contributed R libraries can be downloaded - easily, and free of
charge - from the CRAN repository. Matevz Bren and Vladimir Batagelj are writing
an R library called mixture
([Link] on
compositional data analysis, but this doesn't yet seem to be available on CRAN. Joel
Reynolds has written a set of R/Splus functions
([Link] to
implement various methods in compositional data analysis, based partly on previous
code written by Dean Billheimer. The R code which we have used in this course is
available online at [Link] .
General regression models for compositional data can be fitted by Bayesian methods
using WinBugs ([Link] or the open-
source version OpenBugs.
The spatial models (chapter 4 of this module) can be fitted using GeoBugs
([Link] a spatial modelling
variant of WinBugs.
The GeoBugs code which we have used within this course is available as an appendix.
John Aitchison has written a suite of BASIC programs, called CODA, to implement a
wide range of techniques for compositional data analysis. If you wish to buy CODA,
then you should contact Chapman and Hall directly. We have no experience in using
CODA ourselves, but, according to the INQUA Working Group on Data-Handling
Methods, 1990 ([Link] "...the CODA
programs are easy-to-use and powerful, but output is rather limited and graphics are
poor...".
Smith Ecology ltd. produce and sell an Excel add-in called Compos Analysis
([Link] for implementing many of the
techniques given in Aitchison (1986).
38
6.2 Key Publications
The literature on compositional data analysis is quite extensive, and ranges from the
highly mathematical to the very applied. Most research papers are published in
statistics, geology or economics journals, but papers are also becoming increasingly
common within ecology/biology journals.
The book by Aitchison (1986) remains the seminal work in this area, and a new
edition has recently been published (Aitchison, 2003a). Aitchison outlines the
problems in applying standard statistical methods to compositional data, puts forward
an alternative approach based upon the analysis of log-ratios, and discusses issues
surrounding statistical modelling and inference. In a recent review paper Aitchison
(2003b) gives an overview of the history of compositional data analysis, and of
methodological developments in the subject since 1986.
Ecological applications
Aebischer et al. (1993) use a log-ratio approach to analyse animal radio-tracking data.
Billheimer et al. (2001) show how log-ratio regression models can be used to analyse
ecological data relating to species composition. Elston et al. (1996) show how data on
the diet compositions of animals that are offered a range of options can be analysed
using log-ratio analysis.
6.3 Bibliography
Adolph, C. (2005)
Succession in the Temple: Central Banker Careers and the Politics of Appointment.
Working paper, [Link]
Aitchison, J. (1982).
The statistical analysis of compositional data (with discussion).
Journal of the Royal Statistical Society B, 44, 139-177.
39
Aitchison, J. (1983)
Principal component analysis of compositional data.
Biometrika, 70, 57-65.
Aitchison, J. (1986)
The Statistical Analysis of Compositional Data (1st edn.), Chapman and Hall
(London).
Aitchison, J. (2003a)
Compositional Data Analysis: where are we and where should we be heading ?
Conference paper for the CoDaWORK workshop on Compositional data analysis,
Girona, September 2003,
[Link]
Aitchison, J. (2003b)
The Statistical Analysis of Compositional Data (2nd edn.), Chapman and Hall
(London).
Besag, J. (1974).
Spatial interaction and the statistical analysis of lattice systems.
Journal of the Royal Statistical Society B, 36(2), 192-236.
40
Billheimer, D., Guutorp, P. and Fagan, F. (2001)
Statistical interpretation of species composition.
Journal of the American Statistical Association, 96(456): 1205-1214.
Billheimer, D., Cardoso, T., Freeman, E. Guttorp, P., Ko, H. and Silkey, M.
(1997)
Natural variability of benthic species in the Delaware Bay.
Journal of environmental and ecological statistics, 4:95-115.
Gelman, A., Carlin, J.B., Stern, H.S. & Rubin, D.B. (1995)
Bayesian data analysis, Chapman & Hall/CRC.
Legendre, P. (1993)
Spatial autocorrelation: Trouble or new paradigm ?
Ecology, 74, 1659-1673.
Link, W.A., Cam, E., Nichols, J.D. & Cooch, E.G. (2002)
Of Bugs and Birds: Markov Cain Monte Carlo for hierarchical modeling in wildlife
41
research.
Journal of Wildlife Management, 66, 277-291.
Thomas, A., Best, N., Lunn, D., Arnold, R. and Spiegelhalter, R. (2004)
GeoBUGS User manual, [Link]
42
APPENDIX A: DATA SETS
Algorithm
Let Li denote the latitude of grid cell i.
Simulate the biodiversity index z1i from a normal distribution, N(2.5,0.12), where i =
1,...,2523.
Simulate the limestone index z2i from a normal distribution, N(sin(Li / 250), 0.252),
where i = 1,...,2523.
43
Simulate the proportion of red flowers Xi1 from a normal distribution, N(z1i / 4,
0.0352), where i = 1,...,2523.
Adjust the proportion of red flowers : if less than 0 then set to 0.01, if greater than 1
then set to 0.99
Adjust the proportion of red flowers again : set Xi1 = Xi1 - z2i / 10
Simulate the proportion of blue flowers Xi2 from a normal distribution, N(z1i / 10,
0.0352), where i = 1,...,2523.
Adjust the proportion of blue flowers again : if less than 0 then set to 0.01, if greater
than 1 then set to 0.99
Calculate the proportion of yellow flowers Xi3, by deducting the proportions of red
and blue flowers from one.
Further details of the R-code used to generate the data can be found at
([Link]
For more details, such as initial values, and the data sets see:
[Link]
model
for (g in 1:N) {
for (i in 1 : N) {
for ( j in 1:2 ) {
44
}
for ( q in 1:N ) {
tau[1:2,1:2] ~ dwish(O[,],2);
O[1, 2] <- 0;
O[2, 1] <- 0;
for ( l in 1:2 ) {
a0[l] ~ dflat();
a1[l] ~ dnorm(0,0.0001);
R[1, 2] <- 0;
R[2, 1] <- 0;
45