Created
May 30, 2015 04:07
-
-
Save garyfeng/afa54a1dc455a47ff6bc to your computer and use it in GitHub Desktop.
TraMineR seqdef() is picky. Sometimes you need to define a new data frame just to get it recognized.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I am mystified by how Traminer handles the data format. | |
# Here's the data from the 2015 NAEP Reading tryout study, SC block | |
# where I transformed the data to simplify the structure. | |
# Then I try to use seqformat() or seqdef() to turn the existing data frame | |
# in to a TraMineR object. | |
sc %>% filter(readingTime>0) %>% group_by(student) %>% arrange(readingTime) %>% | |
mutate(c1=1:n(), c2=2:(n()+1), t0=c(1, readingTime[1:n()-1])) %>% | |
select(student, c1, c2, state2, t0, readingTime, event2) %>% na.omit() ->scSPELL | |
scSPELL$student <-factor(scSPELL$student) | |
scSPELL$state2 <-factor(scSPELL$state2) | |
scSPELL$t1<-round(scSPELL$t0/1000)+1 | |
scSPELL$t2<-round(scSPELL$readingTime/1000)+1 | |
# The following code fails | |
# slmax = 60 | |
# sc.sts <- seqformat(scSPELL, from="SPELL", to="STS", begin="c1", end="c2", id="student", status="state2", limit=slmax) | |
# this line fails | |
# sc.sts<- seqdef(scSPELL, 1:4, informat="SPELL", limit=350) | |
# but the following works: first construct a new df | |
sc.spell<-data.frame(scSPELL$student, c1=scSPELL$c1, c2=scSPELL$c2, status=scSPELL$state2) | |
# and then seqdef() | |
sc.sts<- seqdef(sc.spell, 1:4, informat="SPELL", limit=350) | |
cpal(sc.sts) <-c("red", "yellow", "orange", "brown", "gray", "black", "green") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment