我的转移概率矩阵是这样的
BP IP SP
BPBP 0.4586757 0.3772354 0.1640889
IPBP 0.3489484 0.4746654 0.1763862
SPBP 0.3756522 0.4162319 0.2081159
BPIP 0.3646061 0.4640000 0.1713939
IPIP 0.2666122 0.5654956 0.1678922
SPIP 0.3054187 0.4860427 0.2085386
BPSP 0.4125561 0.3974215 0.1900224
IPSP 0.2974337 0.5069415 0.1956247
SPSP 0.3576642 0.4333942 0.2089416
并且从中模拟一阶MC的代码是
function(trans,initprob,N)
{
BrokerPosition <- c("BP", "IP", "SP")
mysequence<-character()
firstposition <- sample(BrokerPosition, 1, rep=TRUE, prob=initprob)
mysequence[1] <- firstposition
for (i in 2:N){
prevposition <- mysequence[i-1]
probabilities <- trans[,prevposition]
BPosition<- sample(BrokerPosition, 1, rep=TRUE, prob=probabilities)
mysequence[i] <- BPosition
}
return(mysequence)
}
但由于这是一个非方阵,我得到一个概率不匹配的错误,知道如何解决这个问题