<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000'>Ok, perfect ! Now I know why it doesn't work. I also know why I have NAs and I can drop them easily, so it's not a problem (the cluster variable is the result of a cluster analysis made previously, before the TraMineR sequence analysis).<br><br>Thanks a lot,<br><br>Hadrien <br><br><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Alexis Gabadinho" <Alexis.Gabadinho@unige.ch><br><b>À: </b>traminer-users@r-forge.wu-wien.ac.at<br><b>Envoyé: </b>Vendredi 16 Mars 2012 13:16:39<br><b>Objet: </b>Re: [Traminer-users] [Traminer-us ers] Re : Re: error splitting sts Object<br><br>
<title></title>
Yes, if you have NA values in your CLUSTER variable then the
expression CLUSTER==1 produces a logical vector containing NAs,
which in turn introduces sequences containing only NA values in your
sequence object when you select cases with CLUSTER==1.<br>
<br>
The solution proposed by Jan surely works. But you should
investigate why you have NA in the CLUSTER variable and make sure
that each row in CLUSTER corresponds to the same observation in your
sequence object. If you have clustered you data using a pairwise
distance matrix computed on your sequence object then there should
not be any NA in your resulting cluster membership vector.<br>
<br>
By the way I would like to mention that Chris and Jan are the first
non-TraMineR-team members to answer a user's question! This is also
what the user's list is intended to. Many thanks to them.<br>
<br>
All the best,<br>
Alexis<br>
<br>
<br>
Le 16. 03. 12 12:54, Jan Goebel a écrit :
<blockquote cite="mid:OFC125790A.00740427-ONC12579C3.00415E33@diw.de"><font face="arial">Try <br>
! ist.na(cluster) & cluster == 1<br>
<br>
Best,<br>
Jan</font><br>
<br>
<div class="domino-section">
<div class="domino-section-head"><span class="domino-section-title"><font color="#424282">Hadrien
Commenges --- [Traminer-users] Re : Re: error splitting
sts Object --- </font></span></div>
<div class="domino-section-body"><br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr valign="top">
<td style="width: 96px;" width="1%"><font color="#5f5f5f" size="2">Von:</font></td>
<td style="width: auto;" width="100%"><font size="2">"Hadrien
Commenges" <a class="moz-txt-link-rfc2396E" href="mailto:hc@parisgeo.cnrs.fr" target="_blank"><hc@parisgeo.cnrs.fr></a></font></td>
</tr>
<tr valign="top">
<td style="width: 96px;" width="1%"><font color="#5f5f5f" size="2">An</font></td>
<td style="width: auto;" width="100%"><font size="2">"Users
questions"
<a class="moz-txt-link-rfc2396E" href="mailto:traminer-users@r-forge.wu-wien.ac.at" target="_blank"><traminer-users@r-forge.wu-wien.ac.at></a></font></td>
</tr>
<tr valign="top">
<td style="width: 96px;" width="1%"><font color="#5f5f5f" size="2">Datum:</font></td>
<td style="width: auto;" width="100%"><font size="2">Fr.,
16.03.2012 12:48</font></td>
</tr>
<tr valign="top">
<td style="width: 96px;" width="1%"><font color="#5f5f5f" size="2">Betreff</font></td>
<td style="width: auto;" width="100%"><font size="2">[Traminer-users]
Re : Re: error splitting sts Object</font></td>
</tr>
</tbody>
</table>
<hr style="color: rgb(128, 145, 165);" align="left" noshade="noshade" size="2" width="100%"><br>
<style> body {height: 100%; color:#000000; font-size:12pt; font-family:Arial, Helvetica, sans-serif;}</style>Thank
you Alexis and Chris for your help. The CLUSTER variable is
not added to the sequence object (a mistake in the first mail)
and it has the same length as the sequence object. This
variable is the result of a cluster analysis and it contains 5
distinct values (groups from 1 to 5) and some NA values. Can
these NA values be a problem even if I select individuals with
a non NA value (like individuals with CLUSTER==1 ?<br>
<br>
<br>
<br>
----- Mail d'origine -----<br>
De: Chris Cameron <a class="moz-txt-link-rfc2396E" href="mailto:cjc73@cornell.edu" target="_blank"><cjc73@cornell.edu></a><br>
À: Users questions
<a class="moz-txt-link-rfc2396E" href="mailto:traminer-users@r-forge.wu-wien.ac.at" target="_blank"><traminer-users@r-forge.wu-wien.ac.at></a><br>
Envoyé: Thu, 15 Mar 2012 20:13:11 +0100 (CET)<br>
Objet: Re: [Traminer-users] error splitting sts Object<br>
<br>
I think Alexis was correct in saying " The vector containing
group membership information should be a standalone vector and
should by no way be added as a further column to your sequence
object." Please examine this further, as the code below
demonstrates that you are introducing an error in your
sequences even if it is not the source of your particular
error message. <br>
<br>
Try not appending the cluster labels vector back into the
sequence object. This definitely changes the sequences in the
subsets (in my example and testing). Though this is not
apparent in your code, I am not sure if your
summary(stsNWObject) was generated before or after you added
the cluster variable.<br>
<br>
In case it helps, I think the nr variable referenced in the
error is a variable that refers to the number of rows. You can
produce an error message that shows nr in this context by
summarizing an empty subset of the sequence object.<br>
<br>
# summary(atus.lim[atus.lim$CLUSTER=='foo',]) #Where "foo" is
not present in the CLUSTER list.<br>
<br>
## atus.lim is the sequence dataset<br>
# atus.lab will be the list of numbers corresponding to the <br>
<br>
# Choose Costs<br>
# Lets suppose that activities that are frequently observed
together are more interchangable<br>
sub_cost = seqsubm(atus.lim, method="TRATE")<br>
# if sequence lengths were equal, then <br>
#indel_cost = 2<br>
indel_cost = .45*max(sub_cost[upper.tri(sub_cost,
diag=FALSE)])<br>
sub_cost <= 2*indel_cost ## Check to see how many subs will
not be allowed (they will be deleted and inserted instead)<br>
<br>
# Compute Distances with Optimal Matching('OM') and costs<br>
seq_dist = seqdist(atus.lim, method='OM', indel=indel_cost,
sm=sub_cost, full.matrix=FALSE)<br>
<br>
# seq.cluster <- agnes(seq_dist, diss = TRUE, method =
"ward")<br>
# The agnes function does not seem to be working, but we can
use hclust<br>
# Using package fastcluster with overwritten hclust<br>
seq.cluster <- hclust(seq_dist, method = "ward") <br>
plot(seq.cluster)<br>
<br>
<br>
# This creates 3 clusters and produces atus.lab, which I think
is what you want stsNWObject$CLUSTER to be<br>
seq.c <- cutree(seq.cluster, k = 3)<br>
atus.lab <- factor(seq.c, labels = paste("c", 1:3))<br>
<br>
# Make a subset:<br>
atus.c1 = atus.lim[atus.lim$CLUSTER=='c 1',]<br>
summary(atus.c1)<br>
<br>
[>] sequence object created with TraMineR version 1.8-1 <br>
[>] 622 sequences in the data set, 619 unique <br>
[>] min/max sequence length: 7/12<br>
[>] alphabet (state labels): <br>
1=1 (Sleep)<br>
2=2 (Groom)<br>
3=3 (Eat)<br>
4=4 (Help)<br>
5=5 (Chores)<br>
6=6 (Work)<br>
7=7 (Local)<br>
8=8 (Relax)<br>
[>] dimensionality of the sequence space: 84 <br>
[>] colors: 1=#7FC97F 2=#BEAED4 3=#FDC086 4=#FFFF99
5=#386CB0 6=#F0027F 7=#BF5B17 8=#666666 <br>
[>] symbol for void element: %<br>
<br>
# Using your method of appending the cluster column to the
sequence data<br>
# Note this changes the length and dimensionality of the
sequences!<br>
atus.lim$CLUSTER <- factor(seq.c, labels = paste(1:3))<br>
atus.c1 = atus.lim[atus.lim$CLUSTER==1,]<br>
summary(atus.c1)<br>
<br>
[>] sequence object created with TraMineR version 1.8-1 <br>
[>] 622 sequences in the data set, 619 unique <br>
[>] min/max sequence length: 8/13<br>
[>] alphabet (state labels): <br>
1=1 (Sleep)<br>
2=2 (Groom)<br>
3=3 (Eat)<br>
4=4 (Help)<br>
5=5 (Chores)<br>
6=6 (Work)<br>
7=7 (Local)<br>
8=8 (Relax)<br>
[>] dimensionality of the sequence space: 91 <br>
[>] colors: 1=#7FC97F 2=#BEAED4 3=#FDC086 4=#FFFF99
5=#386CB0 6=#F0027F 7=#BF5B17 8=#666666 <br>
[>] symbol for void element: % <br>
<br>
seq.c <- cutree(seq.cluster, k = 10)<br>
atus.lim$CLUSTER <- factor(seq.c, labels = paste(1:10))<br>
atus.c1 = atus.lim[atus.lim$CLUSTER==1,]<br>
summary(atus.c1)<br>
<br>
<br>
On Mar 15, 2012, at 1:10 PM, Hadrien Commenges wrote:<br>
<br>
> Hi,<br>
> <br>
> I've created a sts object with the seqdef function and
I'd like to split this object by a factor (cluster). I canuse
some functions with the "group=" option, but I need to work
with smaller objects and I really want to split-Ihre Daten
wurden abgeschnitten.
<pre><fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Traminer-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Traminer-users@lists.r-forge.r-project.org" target="_blank">Traminer-users@lists.r-forge.r-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users</a>
</pre>
</div>
</div>
</blockquote>
<br>
<br>_______________________________________________<br>Traminer-users mailing list<br>Traminer-users@lists.r-forge.r-project.org<br>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users</div><br></div></body></html>