The R Project SVN R

Rev

Rev 74265 | Rev 85953 | Go to most recent revision | 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
74265 hornik 3
% Copyright 1995-2018 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{assocplot}
56186 murdoch 7
\alias{assocplot}
50971 ripley 8
\encoding{UTF-8}
27442 ripley 9
\title{Association Plots}
10
\description{
11
  Produce a Cohen-Friendly association plot indicating deviations from
12
  independence of rows and columns in a 2-dimensional contingency
13
  table.
14
}
15
\usage{
16
assocplot(x, col = c("black", "red"), space = 0.3,
17
          main = NULL, xlab = NULL, ylab = NULL)
18
}
19
\arguments{
20
  \item{x}{a two-dimensional contingency table in matrix form.}
21
  \item{col}{a character vector of length two giving the colors used for
22
    drawing positive and negative Pearson residuals, respectively.}
23
  \item{space}{the amount of space (as a fraction of the average
27625 ripley 24
    rectangle width and height) left between each rectangle.}
27442 ripley 25
  \item{main}{overall title for the plot.}
36139 ripley 26
  \item{xlab}{a label for the x axis.  Defaults to the name (if any) of
27
    the row dimension in \code{x}.}
28
  \item{ylab}{a label for the y axis.  Defaults to the name (if any) of
29
    the column dimension in \code{x}.}
27442 ripley 30
}
31
\details{
32
  For a two-way contingency table, the signed contribution to Pearson's
33
  \eqn{\chi^2}{chi^2} for cell \eqn{i, j} is \eqn{d_{ij} = (f_{ij} -
34
    e_{ij}) / \sqrt{e_{ij}}}{d_{ij} = (f_{ij} - e_{ij}) / sqrt(e_{ij})},
35
  where \eqn{f_{ij}} and \eqn{e_{ij}} are the observed and expected
36
  counts corresponding to the cell.  In the Cohen-Friendly association
37
  plot, each cell is represented by a rectangle that has (signed) height
38
  proportional to \eqn{d_{ij}} and width proportional to
39
  \eqn{\sqrt{e_{ij}}}{sqrt(e_{ij})}, so that the area of the box is
40
  proportional to the difference in observed and expected frequencies.
41
  The rectangles in each row are positioned relative to a baseline
42
  indicating independence (\eqn{d_{ij} = 0}).  If the observed frequency
43
  of a cell is greater than the expected one, the box rises above the
44
  baseline and is shaded in the color specified by the first element of
45
  \code{col}, which defaults to black; otherwise, the box falls below
46
  the baseline and is shaded in the color specified by the second
47
  element of \code{col}, which defaults to red.
37294 hornik 48
 
49
  A more flexible and extensible implementation of association plots
50
  written in the grid graphics system is provided in the function
57939 hornik 51
  \code{\link[vcd]{assoc}} in the contributed package \CRANpkg{vcd}
74265 hornik 52
  (Meyer, Zeileis and Hornik, 2006).
27442 ripley 53
}
54
\seealso{
37294 hornik 55
  \code{\link{mosaicplot}}, \code{\link{chisq.test}}.
27442 ripley 56
}
57
\references{
58
  Cohen, A. (1980),
59
  On the graphical display of the significant components in a two-way
60
  contingency table.
74265 hornik 61
  \emph{Communications in Statistics---Theory and Methods}, \bold{9},
27442 ripley 62
  1025--1041.
74265 hornik 63
  \doi{10.1080/03610928008827940}.
27442 ripley 64
 
65
  Friendly, M. (1992),
66
  Graphical methods for categorical data.
67
  \emph{SAS User Group International Conference Proceedings}, \bold{17},
68
  190--200.
77322 hornik 69
  \url{http://datavis.ca/papers/sugi/sugi17.pdf}
37294 hornik 70
 
74265 hornik 71
  Meyer, D., Zeileis, A., and Hornik, K. (2006)  
72
  The strucplot Framework: Visualizing Multi-Way Contingency Tables with
73
  \pkg{vcd}.
74
  \emph{Journal of Statistical Software}, \bold{17(3)}, 1--48.
75
  \doi{10.18637/jss.v017.i03}.
27442 ripley 76
}
77
\examples{
78
## Aggregate over sex:
79
x <- margin.table(HairEyeColor, c(1, 2))
80
x
81
assocplot(x, main = "Relation between hair and eye color")
82
}
83
\keyword{hplot}