friendly / VCDR

Visualizing categorical data with R
0 stars 0 forks source link

ch08b/toxaemia.Rnw: Fix plot of LOR in Example 10.9 #18

Closed friendly closed 9 years ago

friendly commented 9 years ago

This example needs to be revised for the new loddsratio methods in vcd.

davidjohannesmeyer commented 9 years ago

Starting on p. 413 (bottom), I would use:

margin.table(tox.tab, 2:1) class smoke 1 2 3 4 5 0 417 1135 4703 984 366 1-19 105 406 3054 859 451 20+ 17 52 523 222 90

LOR <- loddsratio(urea ~ hyper | class + smoke, data = tox.tab) LOR log odds ratios for hyper and urea by class, smoke

 smoke

class 0 1-19 20+ 1 1.526791 1.0710243 2.4485390 2 1.461960 0.8640134 -1.1457908 3 1.580565 1.3736951 0.7442513 4 1.313513 1.3426023 0.8846854 5 1.003623 1.0347544 2.0187271

and then simply

plot(LOR)

Small issue: the output of LOR does not match the plot (transposed), because plot.loddsratio puts the first (conditioning) variable on the x-axis, but in the LOR-matrix above, this is represented by the rows. I guess changing this would be confusing in case of more than two conditioning variables. To fix this, we could use

loddsratio(urea ~ hyper | smoke + class, data = tox.tab)

for printing and

plot(loddsratio(urea ~ hyper | class + smoke, data = tox.tab))

for the plot (ugly), or, alternatively, add t() and aperm() methods for loddsratio objects, allowing to use

t(LOR)

for either the textual output or the plot?

davidjohannesmeyer commented 9 years ago

Yet another solution: use

plot(LOR, transpose = TRUE)

friendly commented 9 years ago

The print and plot methods you suggest in your first comment work, but it would be very useful to have t() and aperm() methods for loddsratio objects. I understand now that's why my matplot() example failed. I'll use your suggestions in this revision.

friendly commented 9 years ago

Question: With the formula

LOR <- loddsratio(urea ~ hyper | class + smoke, data = tox.tab)
plot(LOR)

should the ylab be "LOR(hyper/urea)" or "LOR(urea/hyper)"? The former is produced now, but my earlier hand-labeled plot used the later. Perhaps the documentation needs a short details paragraph on how the variables in the formula argument are used to form the odds ratios.

davidjohannesmeyer commented 9 years ago

I had copied the mosaic formula code where it makes sense to order a dependent variable last, in contrast to loddsratio(). Fixed now, so that y ~ x is ~ y + x.