R 条件概率
我试图从以下内容创建一个条件概率矩阵: 我已经重写了没有循环的代码R 条件概率,r,conditional,probability,R,Conditional,Probability,我试图从以下内容创建一个条件概率矩阵: 我已经重写了没有循环的代码 a # Signal Vector b # Price Change Vector Signalt<- seq(0, 1, 0.05) # Produce the 5% tiles abst <- c(seq(1, 1.02, by = 0.0025), 2) #Produce the 0% to 2% tiles with 0.25% increments. Added 1 to include price
a # Signal Vector
b # Price Change Vector
Signalt<- seq(0, 1, 0.05) # Produce the 5% tiles
abst <- c(seq(1, 1.02, by = 0.0025), 2) #Produce the 0% to 2% tiles with 0.25% increments. Added 1 to include price change of 0 in `temp`
xbool = ((Signal >= Signalt[1] & a < Signalt[1 + 1]) *1) # 1 for True 0 for False
temp = (PercChange + 1) * xbool
temp2 <- temp[which(temp > 0)]
CondProb <- cut(temp2, abst, include.lowest = T)
table(CondProb)
a#信号向量
b#价格变化向量
signal t听起来像是要cut
或findInterval
这些函数的输出外观示例
> cut(rnorm(9), breaks = -6:6)
[1] (0,1] (-2,-1] (0,1] (1,2] (0,1] (-1,0] (-2,-1] (0,1] (-1,0]
12 Levels: (-6,-5] (-5,-4] (-4,-3] (-3,-2] (-2,-1] (-1,0] (0,1] (1,2] ... (5,6]
> findInterval(rnorm(9), -6:6)
[1] 7 6 7 6 8 9 7 7 6
我已经编辑了我原来的帖子。我想它是和旧的埋在一起的。你能找出上面的一些错误吗?非常感谢你的帮助,我有点被困在这个问题上了!
> cut(rnorm(9), breaks = -6:6)
[1] (0,1] (-2,-1] (0,1] (1,2] (0,1] (-1,0] (-2,-1] (0,1] (-1,0]
12 Levels: (-6,-5] (-5,-4] (-4,-3] (-3,-2] (-2,-1] (-1,0] (0,1] (1,2] ... (5,6]
> findInterval(rnorm(9), -6:6)
[1] 7 6 7 6 8 9 7 7 6