4

I'd like to plot a transition matrix, but I want 2 columns with every state.

My matrix is:

> 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% goes to 30 and so on.

The thing is that I don't want 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 table of 10x10.... Is there any other way to do the same without having to create such a table?

Mi idea is to get to this graph without having to modify the original table:

To do this I transformed the original matrix with 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

Thanks

Community
  • 1
  • 1
GabyLP
  • 3,649
  • 7
  • 45
  • 66

1 Answers1

0

Here's a plot that may meet your needs (sample code, matrix and package that produces plot): Transition Matrix Plot:

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)