WARD: Ward clustering of a compositional data matrix

View source: R/WARD.r

WARDR Documentation

Ward clustering of a compositional data matrix

Description

This function clusters the rows (or the columns, if the matrix is transformed) of a compositional data matrix, using weighted Ward clustering of the logratios.

Usage

WARD(LRdata, weight=FALSE, row.wt=NA)

Arguments

LRdata

Matrix of logratios, either a vector or preferably the logratio object resulting from one of the functions ALR, CLR, or PLR (usually CLRs will be used))

weight

FALSE (default) for no differential part weighting (i.e., equal weights), TRUE for weights equal to compositional part means, or a user-provided vector of part weights

row.wt

Optional set of row weights (default is equal weights when row.wt=NA)

Details

The function WARD performs a weighted WARD hierarchical clustering on the rows of an input set of logratios, usually CLR-transformed. (This would be equivalent to performing the clustering on all pairwise logratios). The default option weight=FALSE assigns equal weights to the parts. The option weight=TRUE implies that column weights are provided, either in the input list object, or as a vector of user-specified weights using the same weight option. Following the standard R convention of hclust(..., method = "ward.D2"), the heights returned in this object represent the unsquared geometric distances (square roots). To reconstruct or verify the total log-ratio variance decomposition from the tree, you must sum the squares of the heights: sum(tree$height^2) -- see the examples below.

Value

An object which describes the tree produced by the clustering process on the n objects. The object is a list with components:

merge

an n-1 by 2 matrix. Row i of merge describes the merging of clusters at step i of the clustering. If an element j in the row is negative, then observation -j was merged at this stage. If j is positive then the merge was with the cluster formed at the (earlier) stage j of the algorithm. Thus negative entries in merge indicate agglomerations of singletons, and positive entries indicate agglomerations of non-singletons.

height

a set of n-1 real values (non-decreasing for ultrametric trees). The clustering height: that is, the value of the criterion associated with the clustering method for the particular agglomeration.

order

a vector giving the permutation of the original observations suitable for plotting, in the sense that a cluster plot using this ordering and matrix merge will not have crossings of the branches

Author(s)

Michael Greenacre

References

Greenacre, M. (2018, 2026), Compositional Data Analysis in Practice, 1st and 2nd editions Chapman & Hall / CRC.

See Also

hclust, CLR, LR.VAR

Examples

# clustering steps for unweighted and weighted logratios
# for both row- and column-clustering

data(Vegetables)

### WARD -----------------------------------------------------------------------
# clustering steps for unweighted and weighted logratios
# for both row- and column-clustering
data(RomanCups)
cups <- CLOSE(RomanCups)

# unweighted logratios: clustering samples
cups.uclr  <- CLR(cups)
cups.uward <- WARD(cups.uclr)   # weight=FALSE not needed here
plot(cups.uward)
# add up the heights of the nodes
sum(cups.uward$height^2)
# [1] 0.02100676
# check against the total logratio variance
LR.VAR(cups.uclr)
# [1] 0.02100676

# unweighted logratios: clustering parts
tcups <- t(cups)
tcups.uclr  <- CLR(tcups)
tcups.uward <- WARD(tcups.uclr)  
plot(tcups.uward, labels=colnames(cups))
sum(tcups.uward$height^2)
# [1] 0.02100676
LR.VAR(tcups.uclr)
# [1] 0.02100676

# weighted logratios: clustering samples
cups.clr <- CLR(cups, weight=TRUE)
cups.ward <- WARD(cups.clr, weight=TRUE)
plot(cups.ward)
sum(cups.ward$height^2)
# [1] 0.002339335
LR.VAR(cups.clr, weight=TRUE)
# [1] 0.002339335

# weighted logratios: clustering parts
# the default weight=FALSE now gives equal weights
# to the samples (columns of tcups)
tcups.clr  <- CLR(CLOSE(tcups))
tcups.ward <- WARD(tcups.clr, row.wt=colMeans(cups))
plot(tcups.ward, labels=colnames(cups))
sum(tcups.ward$height^2)
# [1] 0.002339335
LR.VAR(tcups.clr, row.wt=colMeans(cups))
# [1] 0.002339335

easyCODA documentation built on Nov. 24, 2026, 1:07 a.m.

Related to WARD in easyCODA...