data(mvad)
## Defining a state sequence object
mvad.seq <- seqdef(mvad[, 17:86])
## Computing dissimilarities (any dissimilarity measure can be used)
mvad.ham <- seqdist(mvad.seq, method="HAM")
dt <- disstree(mvad.ham~ male + Grammar + funemp + gcse5eq + fmpr + livboth,
data=mvad, R = 10)
print(dt)
## Will only work if GraphViz is properly installed
## See seqtree for simpler way to plot a sequence tree.
disstreedisplay(dt, imagefunc=seqdplot, imagedata=mvad.seq,
## Additional parameters passed to seqdplot
withlegend=FALSE, axes=FALSE, ylab="")
## Second method, using a specific function
myplotfunction <- function(individuals, seqs, ...) {
par(font.sub=2, mar=c(3,0,6,0), mgp=c(0,0,0))
## using mds to order sequence in seqiplot
mds <- cmdscale(seqdist(seqs[individuals,], method="HAM"),k=1)
seqiplot(seqs[individuals,], sortv=mds,...)
}
## If imagedata is not set, index of individuals are sent to imagefunc
disstreedisplay(dt, imagefunc=myplotfunction, title.cex=3,
## additional parameters passed to myplotfunction
seqs=mvad.seq,
## additional parameters passed to seqiplot (through myplotfunction)
withlegend=FALSE, axes=FALSE, tlim=0, space=0, ylab="", border=NA)
Run the code above in your browser using DataLab