branch of the tree. Observe that a given variable may be used several times along
the course of the successive binary partitions.
As proposed in the code below, apart from the residuals, one can retrieve the
objects of each node and examine the node’s characteristics at will:
# Residuals of MRT
par(mfrow = c(1, 2))
hist(residuals(spe.ch.mvpart), col = "bisque")
plot(predict(spe.ch.mvpart, type = "matrix"),
residuals(spe.ch.mvpart),
main = "Residuals vs Predicted")
abline(h = 0, lty = 3, col = "grey")
# Group composition
spe.ch.mvpart$where
# Group identity
(groups.mrt <- levels(as.factor(spe.ch.mvpart$where)))
# Fish composition of first leaf
spe.norm[which(spe.ch.mvpart$where == groups.mrt[1]), ]
# Environmental variables of first leaf
env[which(spe.ch.mvpart$where == groups.mrt[1]), ]
One can also use the MRT results to produce pie charts of the fish composition of
the leaves (Fig. 4.28):
# Table and pie charts of fish composition of leaves
leaf.sum <- matrix(0, length(groups.mrt), ncol(spe))
colnames(leaf.sum) <- colnames(spe)
for (i in 1:length(groups.mrt))
{
leaf.sum[i, ]
2, sum)
}
leaf.sum
par(mfrow = c(2, 2))
for (i in 1:length(groups.mrt)) {
pie(which(leaf.sum[i, ] > 0),
radius = 1,
main = paste("leaf #", groups.mrt[i]))
}
Unfortunately, extracting other numerical results from an mvpart() object is
no easy task. This is why our colleague Marie-Hélène Ouellette wrote a wrapper
doing just that and providing a wealth of additional, useful information. The package
132
4 Cluster Analysis
the course of the successive binary partitions.
As proposed in the code below, apart from the residuals, one can retrieve the
objects of each node and examine the node’s characteristics at will:
# Residuals of MRT
par(mfrow = c(1, 2))
hist(residuals(spe.ch.mvpart), col = "bisque")
plot(predict(spe.ch.mvpart, type = "matrix"),
residuals(spe.ch.mvpart),
main = "Residuals vs Predicted")
abline(h = 0, lty = 3, col = "grey")
# Group composition
spe.ch.mvpart$where
# Group identity
(groups.mrt <- levels(as.factor(spe.ch.mvpart$where)))
# Fish composition of first leaf
spe.norm[which(spe.ch.mvpart$where == groups.mrt[1]), ]
# Environmental variables of first leaf
env[which(spe.ch.mvpart$where == groups.mrt[1]), ]
One can also use the MRT results to produce pie charts of the fish composition of
the leaves (Fig. 4.28):
# Table and pie charts of fish composition of leaves
leaf.sum <- matrix(0, length(groups.mrt), ncol(spe))
colnames(leaf.sum) <- colnames(spe)
for (i in 1:length(groups.mrt))
{
leaf.sum[i, ]
}
leaf.sum
par(mfrow = c(2, 2))
for (i in 1:length(groups.mrt)) {
pie(which(leaf.sum[i, ] > 0),
radius = 1,
main = paste("leaf #", groups.mrt[i]))
}
Unfortunately, extracting other numerical results from an mvpart() object is
no easy task. This is why our colleague Marie-Hélène Ouellette wrote a wrapper
doing just that and providing a wealth of additional, useful information. The package
132
4 Cluster Analysis
