## S3 method for class 'default':
assoc(x, row_vars = NULL, col_vars = NULL, compress = TRUE,
xlim = NULL, ylim = NULL,
spacing = spacing_conditional(sp = 0), spacing_args = list(),
split_vertical = NULL, keep_aspect_ratio = FALSE, residuals_type = "Pearson",
xscale = 0.9, yspace = unit(0.5, "lines"), ...)
## S3 method for class 'formula':
assoc(formula, data = NULL, subset, na.action, \dots, main = NULL)
dimnames(x)
attribute, or an object
inheriting from the "ftable"
class (such as
"structable"
objects).FALSE
, the space between the rows
(columns) are chosen such that the total heights (widths) of
the rows (columns) are all equal. If TRUE
, the space between
rows and columns is fixed and hence thexlim
correspond to the columns of the association plot, the rows describe
the column ranges (minimums in the first row, maximums in the secylim
correspond to the rows of the association plot, the rows describe
the column ranges (minimums in the first row, maximums in the second
strucplot
for
more information). The default is the spacing-generating function
strucplot
for more information).x
(values are recycled as needed).
A TRUE
component indicates that the corresponding dimension
is folded into the columns, FALSE
fol"unit"
specifying additional
space separating the rows.data
is a contingency table.NA
s.
Ignored if data
is a contingency table.main
is TRUE
, the
name of the data
object is used.strucplot
"structable"
visualized is returned invisibly. assoc
is a generic function and currently has a default method and a
formula interface. Both are high-level interfaces to the
strucplot
function, and produce (extended) association
plots. Most of the functionality is described there, such as
specification of the independence model, labeling, legend, spacing,
shading, and other graphical parameters.
For a contingency table, the signed contribution to Pearson's $\chi^2$ for cell ${ij\ldots k}$ is $$d_{ij\ldots k} = \frac{(f_{ij\ldots k} - e_{ij\ldots k})}{ \sqrt{e_{ij\ldots k}}}$$ where $f_{ij\ldots k}$ and $e_{ij\ldots k}$ are the observed and expected counts corresponding to the cell. In the association plot, each cell is represented by a rectangle that has (signed) height proportional to $d_{ij\ldots k}$ and width proportional to $\sqrt{e_{ij\ldots k}}$, so that the area of the box is proportional to the difference in observed and expected frequencies. The rectangles in each row are positioned relative to a baseline indicating independence ($d_{ij\ldots k} = 0$). If the observed frequency of a cell is greater than the expected one, the box rises above the baseline, and falls below otherwise.
Additionally, the residuals can be colored depending on a specified
shading scheme (see Meyer et al., 2003). Package
Unlike the assocplot
function in the
"ftable"
or
"structable"
), the dimensions are folded into rows and columns.
The layout is very flexible: the specification of shading, labeling,
spacing, and legend is modularized (see strucplot
for
details).
M. Friendly (1992),
Graphical methods for categorical data.
SAS User Group International Conference Proceedings, 17,
190--200.
mosaic
,
strucplot
,
structable
data(HairEyeColor)
## Aggregate over sex:
(x <- margin.table(HairEyeColor, c(1, 2)))
## Ordinary assocplot:
assoc(x)
## and with residual-based shading (of independence)
assoc(x, main = "Relation between hair and eye color", shade = TRUE)
## Aggregate over Eye color:
(x <- margin.table(HairEyeColor, c(1, 3)))
chisq.test(x)
assoc(x, main = "Relation between hair color and sex", shade = TRUE)
# Visualize multi-way table
assoc(aperm(HairEyeColor), expected = ~ (Hair + Eye) * Sex,
labeling_args = list(just_labels = c(Eye = "left"),
offset = c(right = -0.5),
rot_labels = c(right = 0),
tl_varnames = c(Eye = TRUE))
)
assoc(aperm(UCBAdmissions), expected = ~ (Admit + Gender) * Dept,
compress = FALSE,
labeling_args = list(abbreviate = c(Gender = TRUE), rot_labels = 0)
)
Run the code above in your browser using DataLab