R junction

I would like to build a transition matrix, but I need to have 2 columns with each state.

My matrix:

> R
      0   30   60   90 <NA>
0  0.75 0.37 0.17 0.07 0.97
30 0.15 0.40 0.32 0.02 0.02
60 0.00 0.20 0.19 0.05 0.01
90 0.00 0.00 0.03 0.52 0.00
NA 0.10 0.03 0.29 0.35 0.00

So, from state 0, 75% remains, 15% - up to 30, etc.

The fact is that I do not need the following plot:

library(diagram)
plotmat(R)

enter image description here

Instead, I want 2 columns with each state ... according to this answer I would need to create a 10x10 table .... Is there any other way to do the same without creating such a table?

Mi's idea is to get to this graph without changing the original table:

To do this, I converted the source matrix to the following code:

L<-matrix(nrow = 10, ncol = 10, byrow = TRUE, data = 0)

for (i in 1:(nrow(R))){
    for (j in 1: ncol(R))
{L[i*2,j*2-1]<-R[i,j]
}}

rownames(L)<-c('0','0', '30','30','60','60','90','90','NA','NA')

plotmat(L[1:6,1:6])

enter image description here

thank

+4
source share
1 answer

, ( , , ): :

install.packages("MmgraphR", repos="http://R-Forge.R-project.org")
library(MmgraphR)
##########################################
# Plotting a probability transition matrix
##########################################

trmat<-matrix( c (0.1, 0.05, 0.05, 0.80,
              0.06, 0.02, 0.03, 0.89,
              0.03, 0.01, 0.01, 0.95,
              0, 0, 0, 1), nrow = 4, ncol = 4, byrow = TRUE)

trmatplot(trmat)
+1

All Articles