1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#function to extract matrices
extractMatrices <- function(mcObj) {
require(matlab)
mcObj <- canonicForm(object = mcObj)
#get the indices of transient and absorbing
transIdx <- which(states(mcObj) %in% transientStates(mcObj))
absIdx <- which(states(mcObj) %in% absorbingStates(mcObj))
#get Q, R and I
Q <- as.matrix(mcObj@transitionMatrix[transIdx,transIdx])
R <- as.matrix(mcObj@transitionMatrix[transIdx,absIdx])
I <- as.matrix(mcObj@transitionMatrix[absIdx, absIdx])
#get fundamental matrix
N <- solve(eye(size(Q)) - Q)
#final absorbion probabilities
NR <- N %*% R
#return
out <- list(
canonicalForm = mcObj,
Q = Q,
R = R,
I = I,
N=N,
NR=NR
)
return(out)
}
|