| 42333 |
ripley |
1 |
% File src/library/graphics/man/fourfoldplot.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 88574 |
hornik |
3 |
% Copyright 1995-2025 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{
|
| 88574 |
hornik |
76 |
\bibshow{R:Friendly:1994b}
|
| 27442 |
ripley |
77 |
}
|
|
|
78 |
\seealso{
|
|
|
79 |
\code{\link{mosaicplot}}
|
|
|
80 |
}
|
|
|
81 |
\examples{
|
| 88574 |
hornik |
82 |
## Use the Berkeley admission data as in Friendly (1994).
|
| 27442 |
ripley |
83 |
x <- aperm(UCBAdmissions, c(2, 1, 3))
|
|
|
84 |
dimnames(x)[[2]] <- c("Yes", "No")
|
|
|
85 |
names(dimnames(x)) <- c("Sex", "Admit?", "Department")
|
| 27714 |
ripley |
86 |
stats::ftable(x)
|
| 27442 |
ripley |
87 |
|
|
|
88 |
## Fourfold display of data aggregated over departments, with
|
|
|
89 |
## frequencies standardized to equate the margins for admission
|
|
|
90 |
## and sex.
|
|
|
91 |
## Figure 1 in Friendly (1994).
|
| 77701 |
pd |
92 |
fourfoldplot(marginSums(x, c(1, 2)))
|
| 27442 |
ripley |
93 |
|
|
|
94 |
## Fourfold display of x, with frequencies in each table
|
|
|
95 |
## standardized to equate the margins for admission and sex.
|
|
|
96 |
## Figure 2 in Friendly (1994).
|
|
|
97 |
fourfoldplot(x)
|
|
|
98 |
|
|
|
99 |
## Fourfold display of x, with frequencies in each table
|
|
|
100 |
## standardized to equate the margins for admission. but not
|
|
|
101 |
## for sex.
|
|
|
102 |
## Figure 3 in Friendly (1994).
|
|
|
103 |
fourfoldplot(x, margin = 2)
|
|
|
104 |
}
|
|
|
105 |
\keyword{hplot}
|