<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal>Hi all,<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>I’m having an issue with seqfplot I’m hoping you
can help me with. I have a series of career sequences over a 77-month
observation period for a group of 15,000 or so individuals. I use the
following code to read in my data (including labels), define a color palette,
and drop any observations with missing data:<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>fx
<- read.csv(file="Seq_function.txt", header=FALSE)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>fx.lab
<- c("AD", "CO", "FI", "GM",
"HR", "LE", "MF", "MK", "OT",
"RD", "SC", "SL", "SV")<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>fx.seq
<- seqdef(fx, 2:78, labels=fx.lab)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>attr(fx.seq,"cpal")
<- c(brewer.pal(n=12, name="Set3"), "cyan",
"white")<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>fx
<- fx[!is.na(fx[,78]), ]<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>fx.seq
<- fx.seq[seqlength(fx.seq)==77,] <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal>Then I use TraMineR to calculate the substitution cost
matrix and do optimal matching. Next I use the “cluster”
package to do a cluster analysis and I find that there are 9 prototypical
sequences. I’d like to do a bit of graphing for each of the 9 clusters,
so I run the following code:<o:p></o:p></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>for
(i in 1:k.best.om.fx)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>{<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
seqdplot(fx.seq[pam.best.fx$clustering==i,], withlegend=F,
title=paste("Cluster ", i))<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
seqfplot(fx.seq[pam.best.fx$clustering==i,], withlegend=F,
title=paste("Cluster ", i))<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>}<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>seqlegend(fx.seq)<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>where fx.seq contains my sequences, as shown above;
pam.best.fx is the pam object that came out of the clustering algorithm and pam.best.fx$clustering
contains the index of each actor’s cluster assignment.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>The seqdplot command produces a series of 9 beautiful
distribution plots, one for each cluster. No problem.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>What I want seqfplot to do is, for each cluster, graph out
the frequency of sequences within each cluster, from most frequent on down the
list. To take one example, the medoid of one cluster is 77 observations
of all the same job function – people who stay in sales and don’t
move. People assigned to that cluster should have spent nearly all 77
periods in that function. The output should look like a long sequence of
blocks that are mostly the same color, with another sequence above it that’s
a little bit different, but also mostly all the same color. But instead,
every single block is a different color from the one next to it. There’s
obviously some problem with either how I’m calling the function or how I’m
defining my color palette, but I can’t figure out what it is. I’m
especially perplexed that seqdplot works properly while an identical call to seqfplot
does not. Any ideas? Thanks in advance,<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>All the best,<o:p></o:p></p>
<p class=MsoNormal>Adam<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>--<o:p></o:p></p>
<p class=MsoNormal><span style='font-size:10.0pt'>Adam M. Kleinbaum<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt'>Assistant Professor<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt'>Tuck School of Business<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt'>Dartmouth College<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt'>http://bit.ly/kleinbaum<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt'>603.646.6447<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>