我想知道TraMineR
中是否有用于计算标准偏差的函数。我对进一步增加置信区间seqmtplot
(平均图)感兴趣。
我的序列(我的数据的小样本)
seq_time = seqdef(dt)
seqmeant(seq_time) * 10
在我的特定情况下,我需要将seqmeant
结果乘以10。
第一个问题,是否有内置函数来检索标准偏差?
第二个问题, 有没有办法将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")))
答案 0 :(得分: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
功能。
希望这有帮助。
============
自版本1.8-11以来TraMineR
中可以计算平均时间的标准误差和误差线图。请参阅功能seqmeant
和plot.stslist.meant
的帮助页面。