Problem with plotmat package
On 09/16/2021 09:26 PM, H wrote:
On 09/16/2021 09:00 PM, Jim Lemon wrote:
Okay, that was just my reading of the help page. I hope that I haven't added to the confusion. Jim On Fri, Sep 17, 2021 at 10:50 AM H <agents at meddatainc.com> wrote:
On 09/15/2021 09:40 PM, Jim Lemon wrote:
Oops, your plot On Thu, Sep 16, 2021 at 11:39 AM Jim Lemon <drjimlemon at gmail.com> wrote:
Hi H,
Looking at your example and the help page, it looks to me as though
the plot is consistent with the "A" matrix:
Oz
Rain Nice
Rain 0.25 0.75
Nice 0.60 0.40
# help page
A - square coefficient matrix, specifying the links (rows=to, cols=from).
In your plot (attached):
Rain (col) goes to Rain (row) 0.25
Rain (col) goes to Nice (row) 0.6
Nice (col) goes to Nice (row) 0.4
Nice (col) goes to Rain (row) 0.75
This is a bit confusing, but it seems to do what it says it does.
Jim
On Thu, Sep 16, 2021 at 10:40 AM H <agents at meddatainc.com> wrote:
I am using plotmat 1.6.5 (part of the diagram package) in R 3.6 to plot Markov transition charts but have run into an issue that I was hoping someone could shed light on here. I did e-mail the maintainer over a month ago but have not received a reply.
The issue is that the directional arrows point in the wrong direction. A brief example:
stateNames <- c("Rain", "Nice")
Oz <- matrix(c(0.25, 0.75, 0.6, 0.4), nrow = 2, byrow = TRUE)
rownames(Oz) <- stateNames; colnames(Oz) <- stateNames
plotmat(Oz, pos = c(1, 1), lwd = 1, box.lwd = 2, cex.txt = 0.8, box.size = 0.1, box.type = "circle", box.prop = 0.5, box.col = "light yellow", arr.length = 0.2, arr.width = 0.2, self.cex = 0.4, self.shifty = 0.01, self.shiftx = 0.13, main = "")
In the above example both arrows seem to point in the direction opposite to what I expect. Has anyone encountered this and know how to fix it?
Thanks.
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
I am sorry but I think you have it wrong. A transition probability matrix for the rain/nice scenario would be written: Rain, Nice Rain |0.25, 0.75| Nice |0.60, 0.40| If you sum the transition probabilities for rain or nice, they should each add to 1. Logic dictates if the only two states are rain and nice, and rain continues the next day with a probability of 0.25, nice must have a probability of 0.75. Likewise, the sum of probabilities for nice weather to change to rain, 0.6, and remain the same, 0.4 must add up to 1. I find that the arrow directions are the opposite of what I expect.
I just realized you did identify what the problem was, it was not the arrow direction but that the matrix needed to be transposed before used in plotmat. I am used to transition probability matrices read row-wise where each row adds up to 1. Plotmat expects the transition matrix to be read column-wise where each column adds up to 1. Transposing the original matrix using t() before using it in plotmat() also resolved my own example which is considerably more complex. Thank you for your help!
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Perhaps someone knows if it is possible to position the state boxes more flexibly in plotmat()? I have eight states I plot in four rows of 1-3-3-1 because it makes logical sense to group them this way row-wise. There are transitions between some of the states and the default positioning of the states, the transition arrows and associated transition probabilities makes for not-so-clear figure...