I am trying to create a matrix of the conditional probabilities from this:
The columns will be the percentiles defined by abst while the rows will be 5% tiles defined by signalt. The idea is through the boolean vector to produce 1's where the absolute returns PercChange should be in the columns, and then plot the probabilities for each signalt of this.
I am however not being able to produce an output - can anyone spot the error(s)?
The desired output should look something like the attached image
Thanks in advance
Code:
Signal <- runif(100)
PercChange <- abs((rnorm(100)/100))
signalt <- seq(0, 1, 0.05)
abst <- seq(0, c(0.02:1), 0.0025)
CondDistMat <- matrix(0, nrow = length(signalt), ncol = length(abst))
for(j in 1:length(signalt - 1)){
xbool = (is.na((Signal >= signalt[j] & Signal < signalt[j + 1]) ) * 1)
ysubset = (PercChange * xbool[j] )
CondProb = hist(ysubset, breaks = abst, freq = TRUE)
CondDistMat[signalt, abst] <- CondProb$density
}
I am however not being able to produce an output - can anyone spot the error(s)?
The desired output should look something like the attached image
Thanks in advance