Reputation: 333
I would like to apply the functions available in the WeightedCluster
package to analyze multichannel sequences I obtained through TraMineR
. I am trying so, but due to the fact that multichannel sequences are lists composed by each channel separatedly, I get errors in functions like seqtreedisplay()
and all those which require a sequence object
.
This is an example:
fullsequences <- list(
work_sequence2 = work_sequence[which(rownames(work_sequence) %in% commonid),],
educ_sequence2 = educ_sequence[which(rownames(educ_sequence) %in% commonid),],
part_sequence2 = part_sequence[which(rownames(part_sequence) %in% commonid),],
kid_sequence2 = kid_sequence[which(rownames(kid_sequence) %in% commonid),]
) # a total of 926 with complete sequences on all channels
multidist <- seqdistmc(
channels = fullsequences,
method = "OM",
norm = FALSE,
sm = list("TRATE","TRATE","TRATE","TRATE"),
with.missing=FALSE,
full.matrix=TRUE,
link="sum")
clusterward <- hclust(as.dist(multidist), method = "ward")
seqtreedisplay(as.seqtree(clusterward, ncluster = 5,
seqdata = fullsequences , diss = multidist))
Error in seqlegend(seqdata, fontsize = legend.fontsize, title = "Legend", :
data is not a sequence object, use seqdef function to create one
Is there a method to use the functionalities of WeightedCluster
package upon a multichannel-type object (list of sequences). I am specially interested in using the Partition Around Medioids algorithm with initial ward clusters (function wcKMedioids()
). If it is not possible, which is the best alternative to cluster multichannels in R
?
Thanks a lot in advance!
Upvotes: 2
Views: 761
Reputation: 3669
The as.seqtree
function (from WeightedCluster
) requires an object of class stslist
(as produced by the TraMineR
seqdef
function) as seqdata
argument. In your case, fullsequences
is a list of such objects (the list of parallel sequences), which is NOT itself of class stslist
. This causes the error.
Even if you would be able to define a tree of parallel sequences, the problem would be that the seqtreedisplay
does not know how to plot parallel sequences. This means that you would have to define a plot function for a list of state sequences and, using the more general disstreedisplay
function instead of seqtreedisplay
, pass the plot function as imagefunc
argument.
To summarize, there are two problems. First you need some as.disstree
equivalent of as.seqtree
that would work for hierarchical clustering of non-stslist objects. Second, you need a plot function for parallel sequences. The first problem is purely technical and should be easily solved. The second is more conceptual.
Upvotes: 2