Seqfplot:百分比与最常见序列数量?

4

我将使用R软件包TraMineR计算和分析状态序列。 我希望使用seqfplot命令获得序列频率图。但是,我不想设置要绘制的最常见序列的数量。

seqfplot(mydata.seq, tlim=1:20)

设置最频繁序列的百分比是非常有用的,以便达到示例中的50%。我尝试过以下方式:

seqfplot(mydata.seq, trep = 0.5)

但与 seqrep.grp seqrep 不同的是, seqfplot 命令不支持 trep 选项。我应该创建一个新函数来实现吗?

谢谢。


你应该提供一个可重现的例子和期望的结果。 - agstudy
1个回答

5

你是正确的,trep参数是TraMineR seqrep函数的一个参数,它查找覆盖所有序列至少trep百分比的代表性序列。

如果你特别想要最频繁的序列模式,使得它们的累积百分频率达到50%,那么你需要自己计算选择过滤器。这里是如何使用biofam数据进行计算的。

library(TraMineR)
data(biofam)
bf.seq <- seqdef(biofam[,10:25])

## first retrieve the "Percent" column of the frequency table provided 
## as the  "freq" attribute of the object returned by the seqtab function.

bf.freq <- seqtab(bf.seq, tlim=nrow(bf.seq))
bf.tab <- attr(bf.freq,"freq")
bf.perct <- bf.tab[,"Percent"]

## Compute the cumulated percentages
bf.cumsum <- cumsum(bf.perct)

## Now we can use the cumulated percentage to select
## the wanted patterns
bf.freq50 <- bf.freq[bf.cumsum <= 50,]

## And to plot the frequent patterns
(nfreq <- length(bf.cumsum[bf.cumsum <= 50]))
seqfplot(bf.seq, tlim=1:nfreq)

希望这可以帮助到您。

1
除了你代码的第五行,我猜应该是 bf.tab <- attr(bf.freq,"freq"),对吧? - emanuela.struffolino
1
第六行应该是 bf.perct <- bf.tab[,"Percent"] - emanuela.struffolino

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接