The R Project SVN R

Rev

Rev 27442 | Rev 40284 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27442 ripley 1
\name{fourfoldplot}
2
\alias{fourfoldplot}
3
\title{Fourfold Plots}
4
\description{
5
  Creates a fourfold display of a 2 by 2 by \eqn{k} contingency table on
6
  the current graphics device, allowing for the visual inspection of the
7
  association between two dichotomous variables in one or several
8
  populations (strata).
9
}
10
\usage{
11
fourfoldplot(x, color = c("#99CCFF", "#6699CC"), conf.level = 0.95,
12
             std = c("margins", "ind.max", "all.max"),
13
             margin = c(1, 2), space = 0.2, main = NULL,
14
             mfrow = NULL, mfcol = NULL)
15
}
16
\arguments{
17
  \item{x}{a 2 by 2 by \eqn{k} contingency table in array form, or as a
18
    2 by 2 matrix if \eqn{k} is 1.}
19
  \item{color}{a vector of length 2 specifying the colors to use for the
20
    smaller and larger diagonals of each 2 by 2 table.}
21
  \item{conf.level}{confidence level used for the confidence rings on
22
    the odds ratios.  Must be a single nonnegative number less than 1;
23
    if set to 0, confidence rings are suppressed.}
24
  \item{std}{a character string specifying how to standardize the table.
25
    Must be one of \code{"margins"}, \code{"ind.max"}, or
26
    \code{"all.max"}, and can be abbreviated by the initial letter.
27
    If set to \code{"margins"}, each 2 by 2 table is standardized to
28
    equate the margins specified by \code{margin} while preserving the
29
    odds ratio.  If \code{"ind.max"} or \code{"all.max"}, the tables are
30
    either individually or simultaneously standardized to a maximal cell
31
    frequency of 1.}
32
  \item{margin}{a numeric vector with the margins to equate.  Must be
33
    one of \code{1}, \code{2}, or \code{c(1, 2)} (the default), which
34
    corresponds to standardizing the row, column, or both margins in
35
    each 2 by 2 table.
36
    Only used if \code{std} equals \code{"margins"}.}
37
  \item{space}{the amount of space (as a fraction of the maximal radius
38
    of the quarter circles) used for the row and column lebals.}
39
  \item{main}{character string for the fourfold title.}
40
  \item{mfrow}{a numeric vector of the form \code{c(nr, nc)}, indicating
41
    that the displays for the 2 by 2 tables should be arranged in an
42
    \code{nr} by \code{nc} layout, filled by rows.}
43
  \item{mfcol}{a numeric vector of the form \code{c(nr, nc)}, indicating
44
    that the displays for the 2 by 2 tables should be arranged in an
45
    \code{nr} by \code{nc} layout, filled by columns.}
46
}
47
\details{
48
  The fourfold display is designed for the display of 2 by 2 by \eqn{k}
49
  tables.
50
 
51
  Following suitable standardization, the cell frequencies
52
  \eqn{f_{ij}}{f[i,j]} of each 2 by 2 table are shown as a quarter
53
  circle whose radius is proportional to
54
  \eqn{\sqrt{f_{ij}}}{sqrt(f[i,j])} so that its area is proportional to
55
  the cell frequency.  An association (odds ratio different from 1)
56
  between the binary row and column variables is indicated by the
57
  tendency of diagonally opposite cells in one direction to differ in
58
  size from those in the other direction; color is used to show this
59
  direction.  Confidence rings for the odds ratio allow a visual test of
60
  the null of no association; the rings for adjacent quadrants overlap
61
  iff the observed counts are consistent with the null hypothesis.
62
 
63
  Typically, the number \eqn{k} corresponds to the number of levels of a
64
  stratifying variable, and it is of interest to see whether the
65
  association is homogeneous across strata.  The fourfold display
66
  visualizes the pattern of association.  Note that the confidence rings
67
  for the individual odds ratios are not adjusted for multiple testing.
68
}
69
\references{
70
  Friendly, M. (1994).
71
  A fourfold display for 2 by 2 by \eqn{k} tables.
72
  Technical Report 217, York University, Psychology Department.
73
  \url{http://www.math.yorku.ca/SCS/Papers/4fold/4fold.ps.gz}
74
}
75
\seealso{
76
  \code{\link{mosaicplot}}
77
}
78
\examples{
79
data(UCBAdmissions)
80
## Use the Berkeley admission data as in Friendly (1995).
81
x <- aperm(UCBAdmissions, c(2, 1, 3))
82
dimnames(x)[[2]] <- c("Yes", "No")
83
names(dimnames(x)) <- c("Sex", "Admit?", "Department")
27714 ripley 84
stats::ftable(x)
27442 ripley 85
 
86
## Fourfold display of data aggregated over departments, with
87
## frequencies standardized to equate the margins for admission
88
## and sex.
89
## Figure 1 in Friendly (1994).
90
fourfoldplot(margin.table(x, c(1, 2)))
91
 
92
## Fourfold display of x, with frequencies in each table
93
## standardized to equate the margins for admission and sex.
94
## Figure 2 in Friendly (1994).
95
fourfoldplot(x)
96
 
97
## Fourfold display of x, with frequencies in each table
98
## standardized to equate the margins for admission. but not
99
## for sex.
100
## Figure 3 in Friendly (1994).
101
fourfoldplot(x, margin = 2)
102
}
103
\keyword{hplot}