mosaic3d {vcdExtra} | R Documentation |
3D Mosaic Plots
Description
Produces a 3D mosaic plot for a contingency table (or a link[MASS]{loglm}
model)
using the rgl-package
.
Generalizing the 2D mosaic plot, this begins with a given 3D shape (a unit cube), and successively sub-divides it along the X, Y, Z dimensions according to the table margins, generating a nested set of 3D tiles. The volume of the resulting tiles is therefore proportional to the frequency represented in the table cells. Residuals from a given loglinear model are then used to color or shade each of the tiles.
This is a developing implementation. The arguments and details are subject to change.
Usage
mosaic3d(x, ...)
## S3 method for class 'loglm'
mosaic3d(
x,
type = c("observed", "expected"),
residuals_type = c("pearson", "deviance"),
...)
## Default S3 method:
mosaic3d(
x, expected = NULL,
residuals = NULL,
type = c("observed", "expected"),
residuals_type = NULL,
shape = rgl::cube3d(alpha = alpha),
alpha = 0.5,
spacing = 0.1,
split_dir = 1:3,
shading = shading_basic,
interpolate=c(2,4),
zero_size=.05,
label_edge,
labeling_args = list(),
newpage = TRUE,
box=FALSE,
...)
Arguments
x |
A |
expected |
optionally, for contingency tables,
an array of expected frequencies of the same dimension as |
residuals |
optionally, an array of residuals of the same dimension as |
type |
a character string indicating whether the |
residuals_type |
a character string indicating the type of residuals to be computed when none are
supplied. If residuals is |
shape |
The initial 3D shape on which the mosaic is based. Typically this is a call to an rgl function, and must produce a |
alpha |
Specifies the transparency of the 3D tiles used to compose the 3D mosaic. |
spacing |
A number or vector giving the total amount of space used to separate the 3D tiles along each of the dimensions of the table. The values specified are re-cycled to the number of table dimensions. |
split_dir |
A numeric vector composed of the integers |
shading |
A function, taking an array or vector of residuals for the given model,
returning a vector of colors. At present, only the default
|
interpolate |
a vector of interpolation values for the |
zero_size |
The radius of a small sphere used to mark zero cells in the display. |
label_edge |
A character vector composed of |
labeling_args |
This argument is intended to be used to specify details of the rendering of labels for the table dimensions, but at present has no effect. |
newpage |
logical indicating whether a new page should be created for the plot or not. |
box |
logical indicating whether a bounding box should be drawn around the plot. |
... |
Other arguments passed down to |
Details
Friendly (1995), Friendly [Sect. 4.5](2000) and Theus and Lauer (1999) have all used the idea of 3D mosaic displays to explain various aspects of loglinear models (the iterative proportional fitting algorithm, the structure of various models for 3-way and n-way tables, etc.), but no implementation of 3D mosaics was previously available.
For the default method,
residuals, used to color and shade the 3D tiles, can be passed explicitly,
or, more typically,
are computed as needed from observed and expected frequencies.
In this case, the expected frequencies are optionally computed for a specified
loglinear model given by the expected
argument.
For the loglm method, residuals and observed frequencies are calculated from the model
object.
Value
Invisibly, the list of shape3d
objects used to draw the 3D mosaic,
with names corresponding to the concatenation of the level labels, separated by ":".
Author(s)
Michael Friendly, with the help of Duncan Murdoch and Achim Zeileis
References
Friendly, M. (1995). Conceptual and Visual Models for Categorical Data, The American Statistician, 49, 153-160.
Friendly, M. Visualizing Categorical Data, Cary NC: SAS Institute, 2000. Web materials: http://www.datavis.ca/books/vcd/.
Theus, M. & Lauer, S. R. W. (1999) Visualizing Loglinear Models. Journal of Computational and Graphical Statistics, 8, 396-412.
See Also
loglin
,
loglm
for details on fitting loglinear models
Examples
# 2 x 2 x 2
if(requireNamespace("rgl")){
mosaic3d(Bartlett, box=TRUE)
# compare with expected frequencies under model of mutual independence
mosaic3d(Bartlett, type="expected", box=TRUE)
# 2 x 2 x 3
mosaic3d(Heart, box=TRUE)
}
## Not run:
# 2 x 2 x 2 x 3
# illustrates a 4D table
mosaic3d(Detergent)
# compare 2D and 3D mosaics
demo("mosaic-hec")
## End(Not run)