The R Project SVN R

Rev

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