Detailed description |
This is related to my last bug report in plot.clustrange. I am not sure whether this actually is a bug or an undocumented necessity: When I am trying to print a plot.clustrange with only one quality criteria, I get "Error in 1:ncol(stats) : argument of length 0". However, if I am plotting two criteria with the same data, everything is just fine. Here is a working example:
library(TraMineR)
library(WeightedCluster)
library(RColorBrewer)
data(mvad)
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school",
"training")
mvad.labels <- c("Employment", "Further Education", "Higher Education",
"Joblessness", "School", "Training")
mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")
## Aggregate example data (useful for large datasets)
mvad.agg <- wcAggregateCases(mvad[, c(10:12, 17:86)], weights=mvad$weight)
mvad.agg
## Define sequence objects
mvad.agg.seq <- seqdef(mvad[mvad.agg$aggIndex, 17:86], alphabet = mvad.alphabet,
states = mvad.scodes, labels = mvad.labels,
weights = mvad.agg$aggWeights, xtstep=6)
## Defining cost matrices for OM
subm.trate <- seqsubm(mvad.agg.seq, method="TRATE")
## Computing dissimilarity matrices
mvad.om <- seqdist(mvad.agg.seq, method="OM", sm=subm.trate)
## Cluster quality
wardCluster <- hclust(as.dist(mvad.om), method = "ward.D2",
members = mvad.agg$aggWeights)
wardRange <- as.clustrange(wardCluster, diss = mvad.om,
weights = mvad.agg$aggWeights, ncluster = 20)
plot(wardRange, stat = c("CH"))
plot(wardRange, stat = "CH")
plot(wardRange, stat = c("CH", "CHsq")) |
|