TraMineR - 平均图的标准偏差和 CI
TraMineR - standard deviation and CI for mean plot
我想知道 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")))
目前 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)
要在图上添加误差线,请考虑 Hmisc
包中的 errbar
函数。
希望这对您有所帮助。
============
自版本 1.8-11 起,TraMineR
提供平均时间的标准误差计算和误差线图。请参阅函数 seqmeant
和 plot.stslist.meant
.
的帮助页面
我想知道 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")))
目前 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)
要在图上添加误差线,请考虑 Hmisc
包中的 errbar
函数。
希望这对您有所帮助。
============
自版本 1.8-11 起,TraMineR
提供平均时间的标准误差计算和误差线图。请参阅函数 seqmeant
和 plot.stslist.meant
.