I am making a tree which will eventually turn into a set of arms with probabilities attached to going down each arm, with a value at the end of each arm.
This is the final arm of me tree (I am building it backwards).
require(mc2d)
ndvar(1000)
sderror_dfail<-(0.30-0.86)/1.96
alpha_dfail<-0.62*{{0.62*{1-0.62}/{sderror_dfail*sderror_dfail}}-1}
beta_dfail<-alpha_dfail*{{1-0.62}/0.62}
probs_d_if_fail<-mcstoc(rbetagen,type="V",shape1=alpha_dfail, shape2=beta_dfail,
min=0, max=1)
lots1<-mcdata(1)
test<-lots1-probs_d_if_fail
probs1 <- mcstoc(rempiricalD, values=1:2, type="V", prob= c(probs_d_if_fail,test))
The next step is to build a branch of a tree as follows:
node1 <- mcprobtree(probs1, list("1"=mcdata(0), "2"=mcdata(1), type="V")
However the line probs1<- mcstoc(….) when I run it gives me the following error
Error in function (n, values, prob = NULL) :
Prob and values should be of same length or have the same number of columns.
I get the feeling it doesn’t like me using mcstoc object as the prob=c(probs_d_if_fail,test) part of the equation, but am not sure how to work around this.
Any help would be greatly appreciated.
Timothy
rempiricalDrequires a a multivariate mcnode asprobargument. This is tricky.Try:
But the following code might be simpler if it fits your needs:
Note that
rbernwill provide a 1 with probability (1-probs_d_if_fail), as you need if I understand well.RP