2

我想知道是否有TraMineR计算标准偏差的函数。我对进一步添加置信区间非常感兴趣seqmtplot(平均图)添加置信区间非常感兴趣。

我的序列(我的数据的小样本)

seq_time = seqdef(dt)
seqmeant(seq_time) * 10 

在我的特殊情况下,我需要乘以 10seqmeant

第一个问题,是否有内置函数来检索标准偏差?

第二个问题,有没有办法将 CI 添加到

seqmtplot(seq_time)

在此处输入图像描述

非常感谢。

样本

   dt = structure(c("e nuclear and acquaintance", "d nuclear", "d nuclear", 
"d nuclear", "e nuclear and acquaintance", "j work study sleep", 
"d nuclear", "a alone", "j work study sleep", "c child", "e nuclear and acquaintance", 
"d nuclear", "d nuclear", "d nuclear", "e nuclear and acquaintance", 
"j work study sleep", "d nuclear", "a alone", "j work study sleep", 
"c child", "e nuclear and acquaintance", "d nuclear", "d nuclear", 
"d nuclear", "e nuclear and acquaintance", "j work study sleep", 
"d nuclear", "a alone", "j work study sleep", "c child", "d nuclear", 
"d nuclear", "d nuclear", "d nuclear", "e nuclear and acquaintance", 
"j work study sleep", "d nuclear", "c child", "j work study sleep", 
"c child", "d nuclear", "d nuclear", "d nuclear", "d nuclear", 
"e nuclear and acquaintance", "j work study sleep", "d nuclear", 
"c child", "j work study sleep", "c child", "d nuclear", "d nuclear", 
"d nuclear", "d nuclear", "e nuclear and acquaintance", "a alone", 
"d nuclear", "c child", "j work study sleep", "c child", "d nuclear", 
"d nuclear", "d nuclear", "d nuclear", "e nuclear and acquaintance", 
"a alone", "d nuclear", "c child", "j work study sleep", "c child", 
"d nuclear", "d nuclear", "d nuclear", "d nuclear", "e nuclear and acquaintance", 
"b partner", "d nuclear", "c child", "j work study sleep", "c child", 
"d nuclear", "d nuclear", "d nuclear", "d nuclear", "e nuclear and acquaintance", 
 "d nuclear", "d nuclear", "c child", "j work study sleep", "c child", 
"d nuclear", "d nuclear", "e nuclear and acquaintance", "e nuclear and acquaintance", 
"e nuclear and acquaintance", "d nuclear", "d nuclear", "c child", 
"j work study sleep", "c child", "d nuclear", "d nuclear", "e nuclear and acquaintance", 
"e nuclear and acquaintance", "e nuclear and acquaintance", "d nuclear", 
 "d nuclear", "d nuclear", "j work study sleep", "c child"), .Dim = 10:11, .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), c("10:30", 
"10:40", "10:50", "11:00", "11:10", "11:20", "11:30", "11:40", 
"11:50", "12:00", "12:10")))
4

1 回答 1

2

目前没有内置函数TraMineR来获取在状态中花费的时间的标准偏差。以下是如何计算此标准偏差和在不同状态下花费的平均时间的标准误差

dt.statd <- seqistatd(dt_time)

mt <- apply(dt.statd, 2, mean)
sdt <- apply(dt.statd, 2, sd)
se.mt <- sdt/sqrt(nrow(dt.statd))
## using 2*se.mt as approximate error margins
mtime <- data.frame(mean = mt, sdev = sdt, se.mean = se.mt, ci.L=mt-2*se.mt, ci.U=mt+2*se.mt)

round(mtime, 3)

如果您有加权序列,则必须考虑加权均值和标准差。这是一个带有mvad数据的示例

library(TraMineR)
data(mvad)
mvad.lab <- c("employment", "further education", "higher education",
              "joblessness", "school", "training")
mvad.shortlab <- c("EM", "FE", "HE", "JL", "SC", "TR")
mvad.seq <- seqdef(mvad[, 17:86], states = mvad.shortlab,
                   labels = mvad.lab, weights = mvad$weight, xtstep = 6)

## state distribution in each sequence
mvad.statd <- seqistatd(mvad.seq)

library(SDMTools) ## for weighted mean and std
mt <- apply(mvad.statd, 2, wt.mean, w = mvad$weight)
sdt <- apply(mvad.statd, 2, wt.sd, w = mvad$weight)
se.mt <- sdt/sqrt(sum(mvad$weight))
mtime <- data.frame(mean = mt, sdev = sdt, se.mean = se.mt)
round(mtime, 3)

要在绘图上添加误差线,请考虑包中的errbar函数Hmisc

希望这可以帮助。

=============

TraMineR从 1.8-11 版本开始可以计算平均时间的标准误差和误差线图。seqmeant请参阅函数和的帮助页面plot.stslist.meant

于 2015-07-30T08:18:28.497 回答