##seriate dist
data("iris")
x <- as.matrix(iris[-5])
x <- x[sample(1:nrow(x)),]
d <- dist(x)
## default seriation
order <- seriate(d)
order
## plot
def.par <- par(no.readonly = TRUE)
layout(cbind(1,2), respect = TRUE)
pimage(d, main = "Random")
pimage(d, order, main = "Reordered")
par(def.par)
## compare quality
rbind(
random = criterion(d),
reordered = criterion(d, order)
)
## seriate matrix
data("iris")
x <- as.matrix(iris[-5])
## to make the variables comparable, we scale the data
x <- scale(x, center = FALSE)
## try some methods
def.par <- par(no.readonly = TRUE)
layout(matrix(1:4, ncol = 2, byrow = TRUE), respect=TRUE)
pimage(x, main = "original data")
criterion(x)
order <- seriate(x, method = "BEA_TSP")
pimage(x, order, main = "TSP to optimize ME")
criterion(x, order)
order <- seriate(x, method="PCA")
pimage(x, order, main = "first principal component")
criterion(x, order)
## 2 TSPs
order <- c(
seriate(dist(x), method = "TSP"),
seriate(dist(t(x)), method = "TSP")
)
pimage(x, order, main = "2 TSPs")
criterion(x, order)
par(def.par)
Run the code above in your browser using DataLab