Closed friendly closed 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?
Yet another solution: use
plot(LOR, transpose = TRUE)
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.
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.
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.
This example needs to be revised for the new loddsratio methods in vcd.