【发布时间】:2019-05-23 16:01:01
【问题描述】:
我想确定一段时间内的活动变化。下面是我用来计算活动之间转移概率的矩阵示例(从 act1_1 到 act1_16)。
head(活动)将返回 一个小标题:6 x 145
serial act1_1 act1_2 act1_3 act1_4 act1_5 act1_6 act1_7 act1_8 act1_9 act1_10
1 1.22e7 110 110 110 110 110 110 110 110 110 110
2 1.43e7 110 110 110 110 110 110 110 110 110 110
3 2.00e7 110 110 110 110 110 110 110 110 110 110
4 2.71e7 110 110 110 110 110 110 110 110 110 110
5 1.61e7 110 110 110 110 110 110 110 110 110 110
6 1.60e7 110 110 110 110 110 110 110 110 110 110
# ... with 134 more variables: act1_11 <dbl+lbl>, act1_12 <dbl+lbl>,
“活动”矩阵的维度是 ncol=144 和 nrows=16533; act1_1...ac1_144 是时间步长,时间以 10 分钟间隔表示(例如 act1_1 = 4.10am;act1_2=4.20am..)。时间从凌晨 4 点 (act1_1) 开始,到 act1_144(4am) 结束。各列填满了不同的活动,例如 110=睡觉、111=看电视、123=吃饭等。
在我正在使用的函数下方calculate the transition probabilities:
transition.matrix <- function(X, prob=T)
{
tt <- table( c(X[,-ncol(X)]), c(X[,-1]) )
if(prob) t <- tt / rowSums(tt)
tt
}
I call the function as:
transitionfunction <- trans.matrix(as.matrix(Activities))
使用这个函数,我设法计算了活动之间的转移概率(活动矩阵)。下面是这种矩阵的一个例子:
使用transitionfunctionI would like to plot on x axis time (10 minutes intervals) and y axis probabilities。
我该怎么做?如何确定活动之间最频繁的转换?
这是我的目标:
【问题讨论】:
-
也许
matplot() -
@Darren Tsai 谢谢,我用 matplot 更新了(见问题结尾)
-
@Darren Tsai 感谢我更新并包含了转移概率矩阵
标签: r dataframe matrix ggplot2