The R Project SVN R

Rev

Rev 88568 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/graphics/man/assocplot.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
88529 hornik 3
% Copyright 1995-2025 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{assocplot}
56186 murdoch 7
\alias{assocplot}
27442 ripley 8
\title{Association Plots}
9
\description{
10
  Produce a Cohen-Friendly association plot indicating deviations from
11
  independence of rows and columns in a 2-dimensional contingency
12
  table.
13
}
14
\usage{
15
assocplot(x, col = c("black", "red"), space = 0.3,
16
          main = NULL, xlab = NULL, ylab = NULL)
17
}
18
\arguments{
19
  \item{x}{a two-dimensional contingency table in matrix form.}
20
  \item{col}{a character vector of length two giving the colors used for
21
    drawing positive and negative Pearson residuals, respectively.}
22
  \item{space}{the amount of space (as a fraction of the average
27625 ripley 23
    rectangle width and height) left between each rectangle.}
27442 ripley 24
  \item{main}{overall title for the plot.}
36139 ripley 25
  \item{xlab}{a label for the x axis.  Defaults to the name (if any) of
26
    the row dimension in \code{x}.}
27
  \item{ylab}{a label for the y axis.  Defaults to the name (if any) of
28
    the column dimension in \code{x}.}
27442 ripley 29
}
30
\details{
31
  For a two-way contingency table, the signed contribution to Pearson's
90253 hornik 32
  \eqn{\chi^2} for cell \eqn{i, j} is \eqn{d_{ij} = (f_{ij} -
27442 ripley 33
    e_{ij}) / \sqrt{e_{ij}}}{d_{ij} = (f_{ij} - e_{ij}) / sqrt(e_{ij})},
34
  where \eqn{f_{ij}} and \eqn{e_{ij}} are the observed and expected
35
  counts corresponding to the cell.  In the Cohen-Friendly association
36
  plot, each cell is represented by a rectangle that has (signed) height
37
  proportional to \eqn{d_{ij}} and width proportional to
38
  \eqn{\sqrt{e_{ij}}}{sqrt(e_{ij})}, so that the area of the box is
39
  proportional to the difference in observed and expected frequencies.
40
  The rectangles in each row are positioned relative to a baseline
41
  indicating independence (\eqn{d_{ij} = 0}).  If the observed frequency
42
  of a cell is greater than the expected one, the box rises above the
43
  baseline and is shaded in the color specified by the first element of
44
  \code{col}, which defaults to black; otherwise, the box falls below
45
  the baseline and is shaded in the color specified by the second
46
  element of \code{col}, which defaults to red.
37294 hornik 47
 
48
  A more flexible and extensible implementation of association plots
49
  written in the grid graphics system is provided in the function
57939 hornik 50
  \code{\link[vcd]{assoc}} in the contributed package \CRANpkg{vcd}
88529 hornik 51
  \bibcitep{R:Meyer+Zeileis+Hornik:2006}.
27442 ripley 52
}
53
\seealso{
37294 hornik 54
  \code{\link{mosaicplot}}, \code{\link{chisq.test}}.
27442 ripley 55
}
56
\references{
88543 hornik 57
  \bibshow{*, R:Cohen:1980, R:Friendly:1992a}
27442 ripley 58
}
59
\examples{
60
## Aggregate over sex:
77701 pd 61
x <- marginSums(HairEyeColor, c(1, 2))
27442 ripley 62
x
63
assocplot(x, main = "Relation between hair and eye color")
64
}
65
\keyword{hplot}