Creates a fourfold display of a 2 by 2 by *k* contingency table on
the current graphics device, allowing for the visual inspection of the
association between two dichotomous variables in one or several
populations (strata).

1 2 3 4 5 |

`x` |
a 2 by 2 by |

`color` |
a vector of length 2 specifying the colors to use for the smaller and larger diagonals of each 2 by 2 table. |

`conf.level` |
confidence level used for the confidence rings on the odds ratios. Must be a single nonnegative number less than 1; if set to 0, confidence rings are suppressed. |

`std` |
a character string specifying how to standardize the table.
Must match one of |

`margin` |
a numeric vector with the margins to equate. Must be
one of |

`space` |
the amount of space (as a fraction of the maximal radius of the quarter circles) used for the row and column labels. |

`main` |
character string for the fourfold title. |

`mfrow` |
a numeric vector of the form |

`mfcol` |
a numeric vector of the form |

The fourfold display is designed for the display of 2 by 2 by *k*
tables.

Following suitable standardization, the cell frequencies
*f[i,j]* of each 2 by 2 table are shown as a quarter
circle whose radius is proportional to
*sqrt(f[i,j])* so that its area is proportional to
the cell frequency. An association (odds ratio different from 1)
between the binary row and column variables is indicated by the
tendency of diagonally opposite cells in one direction to differ in
size from those in the other direction; color is used to show this
direction. Confidence rings for the odds ratio allow a visual test of
the null of no association; the rings for adjacent quadrants overlap
if and only if the observed counts are consistent with the null hypothesis.

Typically, the number *k* corresponds to the number of levels of a
stratifying variable, and it is of interest to see whether the
association is homogeneous across strata. The fourfold display
visualizes the pattern of association. Note that the confidence rings
for the individual odds ratios are not adjusted for multiple testing.

Friendly, M. (1994).
A fourfold display for 2 by 2 by *k* tables.
Technical Report 217, York University, Psychology Department.
http://datavis.ca/papers/4fold/4fold.pdf

`mosaicplot`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ```
## Use the Berkeley admission data as in Friendly (1995).
x <- aperm(UCBAdmissions, c(2, 1, 3))
dimnames(x)[[2]] <- c("Yes", "No")
names(dimnames(x)) <- c("Sex", "Admit?", "Department")
stats::ftable(x)
## Fourfold display of data aggregated over departments, with
## frequencies standardized to equate the margins for admission
## and sex.
## Figure 1 in Friendly (1994).
fourfoldplot(marginSums(x, c(1, 2)))
## Fourfold display of x, with frequencies in each table
## standardized to equate the margins for admission and sex.
## Figure 2 in Friendly (1994).
fourfoldplot(x)
## Fourfold display of x, with frequencies in each table
## standardized to equate the margins for admission. but not
## for sex.
## Figure 3 in Friendly (1994).
fourfoldplot(x, margin = 2)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.