多通道序列对象的绘制和排序
Plotting and sorting of multi-channel sequence objects
我想制作一个多通道序列对象的序列索引图,用于第一个描述目的。但是,我仍然不确定如何正确地做到这一点。对一个序列对象进行排序的常用方法效果不佳,因为没有跨多个通道进行排序的嵌套排序函数。在我看来,最好的方法是在使用 seqdistmc 计算多通道序列距离后进行 MDS,并相应地对所有通道进行排序。这种方法需要在距离测量等方面做出多项决定,因此它几乎超出了我最初描述的意图。
- 是否可以通过某种方式创建嵌套排序函数
对于多通道序列对象?也许通过排序第一个
从序列的开头开始通道,然后对“领带”进行排序,
相等的序列,通过对第二个通道进行排序等等?
更新:我使用seqHMM
找到了这部分问题的答案,见下文。
- 你怎么看,绘制和排序的最佳方法是什么
用于描述的多通道序列对象?
这里有一些 R 语法,可能有助于理解我的问题
library(TraMineR)
library(TraMineRextras)
# Building sequence objects
data(biofam)
## Building one channel per type of event left, children or married
bf <- as.matrix(biofam[, 10:25])
children <- bf==4 | bf==5 | bf==6
married <- bf == 2 | bf== 3 | bf==6
left <- bf==1 | bf==3 | bf==5 | bf==6
child.seq <- seqdef(children)
marr.seq <- seqdef(married)
left.seq <- seqdef(left)
# Create unsorted Sequence Index Plots
layout(matrix(c(1,2,3,4,4,4), 2, 3, byrow=TRUE), heights=c(3,1.5))
seqIplot(child.seq, title="Children", withlegend=FALSE)
seqIplot(marr.seq, title="Married", withlegend=FALSE)
seqIplot(left.seq, title="Left parents", withlegend=FALSE)
seqlegend(child.seq, horiz=TRUE, position="top", xpd=TRUE)
# Create sequence Index Plots sorted by alignment of first channel from beginning
mcsort.ch1 <- sortv(child.seq, start="beg")
layout(matrix(c(1,2,3,4,4,4), 2, 3, byrow=TRUE), heights=c(3,1.5))
seqIplot(child.seq, title="Children", sortv=mcsort.ch1, withlegend=FALSE)
seqIplot(marr.seq, title="Married", sortv=mcsort.ch1, withlegend=FALSE)
seqIplot(left.seq, title="Left parents", sortv=mcsort.ch1, withlegend=FALSE)
seqlegend(child.seq, horiz=TRUE, position="top", xpd=TRUE)
# Sequence Index Plots sorted by MDS scores of multi-channel distances
## Calculate multi-channel distances and MDS scores
mcdist <- seqdistmc(channels=list(child.seq, marr.seq, left.seq),
method="OM", sm =list("TRATE", "TRATE", "TRATE"))
mcsort.mds <- cmdscale(mcdist, k=2, eig=TRUE)
## Create sequence Index Plots sorted by MDS scores of multi-channel distances
layout(matrix(c(1,2,3,4,4,4), 2, 3, byrow=TRUE), heights=c(3,1.5))
seqIplot(child.seq, title="Children", sortv=mcsort.mds$points[,1], withlegend=FALSE)
seqIplot(marr.seq, title="Married", sortv=mcsort.mds$points[,1], withlegend=FALSE)
seqIplot(left.seq, title="Left parents", sortv=mcsort.mds$points[,1], withlegend=FALSE)
seqlegend(child.seq, horiz=TRUE, position="top", xpd=TRUE)
我只是偶然发现了包 seqHMM
,它的名字暗示了其他用途,但它能够对多通道序列对象进行排序。因此,seqHMM
是我第一个问题的答案。
这是使用 seqHMM
:
的示例代码
library(TraMineR)
library(seqHMM)
# Building sequence objects
data(biofam)
## Building one channel per type of event left, children or married
bf <- as.matrix(biofam[, 10:25])
children <- bf==4 | bf==5 | bf==6
married <- bf == 2 | bf== 3 | bf==6
left <- bf==1 | bf==3 | bf==5 | bf==6
child.seq <- seqdef(children)
marr.seq <- seqdef(married)
left.seq <- seqdef(left)
mcplot <- ssp(list(child.seq, marr.seq, left.seq),
type = "I",title = "Sequence index plots",
sortv = "from.start", sort.channel = 1,
withlegend = FALSE, ylab.pos = c(1, 1.5, 1),
ylab = c("Parenthood", "Marriage", "Residence"))
plot(mcplot)
您可以在以下论文中找到有关包功能的更多信息:
赫尔斯基,萨图; Helske, Jouni (2016):序列数据的混合隐马尔可夫模型:R. Jyväskylä 中的 seqHMM 包。可在 https://cran.r-project.org/web/packages/seqHMM/vignettes/seqHMM.pdf.
在线获取
我想制作一个多通道序列对象的序列索引图,用于第一个描述目的。但是,我仍然不确定如何正确地做到这一点。对一个序列对象进行排序的常用方法效果不佳,因为没有跨多个通道进行排序的嵌套排序函数。在我看来,最好的方法是在使用 seqdistmc 计算多通道序列距离后进行 MDS,并相应地对所有通道进行排序。这种方法需要在距离测量等方面做出多项决定,因此它几乎超出了我最初描述的意图。
- 是否可以通过某种方式创建嵌套排序函数
对于多通道序列对象?也许通过排序第一个
从序列的开头开始通道,然后对“领带”进行排序,
相等的序列,通过对第二个通道进行排序等等?
更新:我使用seqHMM
找到了这部分问题的答案,见下文。 - 你怎么看,绘制和排序的最佳方法是什么 用于描述的多通道序列对象?
这里有一些 R 语法,可能有助于理解我的问题
library(TraMineR)
library(TraMineRextras)
# Building sequence objects
data(biofam)
## Building one channel per type of event left, children or married
bf <- as.matrix(biofam[, 10:25])
children <- bf==4 | bf==5 | bf==6
married <- bf == 2 | bf== 3 | bf==6
left <- bf==1 | bf==3 | bf==5 | bf==6
child.seq <- seqdef(children)
marr.seq <- seqdef(married)
left.seq <- seqdef(left)
# Create unsorted Sequence Index Plots
layout(matrix(c(1,2,3,4,4,4), 2, 3, byrow=TRUE), heights=c(3,1.5))
seqIplot(child.seq, title="Children", withlegend=FALSE)
seqIplot(marr.seq, title="Married", withlegend=FALSE)
seqIplot(left.seq, title="Left parents", withlegend=FALSE)
seqlegend(child.seq, horiz=TRUE, position="top", xpd=TRUE)
# Create sequence Index Plots sorted by alignment of first channel from beginning
mcsort.ch1 <- sortv(child.seq, start="beg")
layout(matrix(c(1,2,3,4,4,4), 2, 3, byrow=TRUE), heights=c(3,1.5))
seqIplot(child.seq, title="Children", sortv=mcsort.ch1, withlegend=FALSE)
seqIplot(marr.seq, title="Married", sortv=mcsort.ch1, withlegend=FALSE)
seqIplot(left.seq, title="Left parents", sortv=mcsort.ch1, withlegend=FALSE)
seqlegend(child.seq, horiz=TRUE, position="top", xpd=TRUE)
# Sequence Index Plots sorted by MDS scores of multi-channel distances
## Calculate multi-channel distances and MDS scores
mcdist <- seqdistmc(channels=list(child.seq, marr.seq, left.seq),
method="OM", sm =list("TRATE", "TRATE", "TRATE"))
mcsort.mds <- cmdscale(mcdist, k=2, eig=TRUE)
## Create sequence Index Plots sorted by MDS scores of multi-channel distances
layout(matrix(c(1,2,3,4,4,4), 2, 3, byrow=TRUE), heights=c(3,1.5))
seqIplot(child.seq, title="Children", sortv=mcsort.mds$points[,1], withlegend=FALSE)
seqIplot(marr.seq, title="Married", sortv=mcsort.mds$points[,1], withlegend=FALSE)
seqIplot(left.seq, title="Left parents", sortv=mcsort.mds$points[,1], withlegend=FALSE)
seqlegend(child.seq, horiz=TRUE, position="top", xpd=TRUE)
我只是偶然发现了包 seqHMM
,它的名字暗示了其他用途,但它能够对多通道序列对象进行排序。因此,seqHMM
是我第一个问题的答案。
这是使用 seqHMM
:
library(TraMineR)
library(seqHMM)
# Building sequence objects
data(biofam)
## Building one channel per type of event left, children or married
bf <- as.matrix(biofam[, 10:25])
children <- bf==4 | bf==5 | bf==6
married <- bf == 2 | bf== 3 | bf==6
left <- bf==1 | bf==3 | bf==5 | bf==6
child.seq <- seqdef(children)
marr.seq <- seqdef(married)
left.seq <- seqdef(left)
mcplot <- ssp(list(child.seq, marr.seq, left.seq),
type = "I",title = "Sequence index plots",
sortv = "from.start", sort.channel = 1,
withlegend = FALSE, ylab.pos = c(1, 1.5, 1),
ylab = c("Parenthood", "Marriage", "Residence"))
plot(mcplot)
您可以在以下论文中找到有关包功能的更多信息:
赫尔斯基,萨图; Helske, Jouni (2016):序列数据的混合隐马尔可夫模型:R. Jyväskylä 中的 seqHMM 包。可在 https://cran.r-project.org/web/packages/seqHMM/vignettes/seqHMM.pdf.