fourfold SAS/IML modules for four-fold display of 2 x 2 x k tables fourfold

Visualizing Categorical Data: fourfold

$Version: 2.0
Michael Friendly
York University

The fourfold macro ( [download] get fourfold.sas)

SAS/IML modules for four-fold display of 2 x 2 x k tables

The FOURFOLD program is a collection of SAS/IML modules for constructing fourfold displays of a 2 x 2 table, or a collection of 2 x 2 tables for multiple strata or groups.

Usage

The modules are typically loaded into the SAS/IML workspace with the %include statement. The required inputs consist of the contingency table, its dimensions, the variable names, and names for the variable levels. These are usually specified with SAS/IML statements, and the fourfold module is called as follows,
proc iml;
   %include iml(fourfold);
  *-- specify required parameters;
   dim =    { ... };   *-- table dimensions;
   table  = { ... };   *-- contingency table;
   vnames = { ... };   *-- variable names;
   lnames = { ... };   *-- level names;
  *-- specify desired global variables;
   config = {1};
   run fourfold( dim, table, vnames, lnames );
The FOURFOLD program also provides a variety of optional parameters to be specified as global SAS/IML variables. All of these are given default values if not specified.

Required parameters

The required parameters for the run fourfold statement are listed below. These are positional parameters, and may be given any valid SAS name in the PROC IML step.
dim
A numeric vector containing the dimensions of the contingency table. The first two elements must be {2 2}.
table
A numeric matrix containing dim[1]=2 columns and number of rows equal to the product of the remaining elements of dim. The table must be entered so that the first variable varies most quickly (row-major order), and the last variable varies most slowly, in accord with the conventions for multiway tables used by the SAS/IML routines marg and ipf.
vnames
A 1 x ncol(dim) character vector, containing the names of the variables in the order corresponding to dim.
lnames
A character matrix containing the names of the categories (levels) of the variables, whose rows correspond to dim and vnames. Any short rows must be filled in with blank character strings, because matrices in SAS/IML must have the same number of elements in each row. For example, for the 2 x 2 x 6 table for the Berkeley data, the dim, vnames and lnames may be entered as follows:
   dim = {2 2 6};
   vnames = {'Admit?' 'Sex' 'Department'};
   lnames = {'Yes' 'No' ' '  ' '  ' '  ' ',
             'Male'  'Female' ' '  ' '  ' '  ' ',
             'A' 'B' 'C' 'D' 'E' 'F'};

Global input variables

The following global variables are used by the program if they have been assigned values of the correct type (character or numeric). Since they all have default values, it is only necessary to specify those you wish to change. All character-valued variables are case-insensitive.
std
Specifies how the 2 x 2 tables are standardized. [Default: std='MARG'.
MARG
standardizes each 2 x 2 table to equal margins, keeping the odds ratio fixed. The config variable determines which margins are equated.
MAX
standardizes each table to a maximum cell frequency of 100. This has the effect of equating the totals in each table.
MAXALL
standardizes all tables so that the maximum cell entry is 100.
config
specifies the margins to standardize, when std='MARG'. config={1 2} equates both the row and column variable in each table; config={1} equates the margin only for the column variable in each table; config={2} equates only the row variable.
down
Specifies the number of fourfold panels down each page
across
Specifies the number of panels across each page
sangle
The angle for side labels (0 | 90). [Default: sangle=90].
colors
The names of two colors to use for the smaller and larger diagonals of each 2x2 table. The positions of first color indicate the direction of association. [Default: colors={BLUE RED}].
patterns
The names of two fill patterns. For grayscale, use patterns={SOLID SOLID} and colors={GRAYC0 GRAY80}. [Default: patterns={SOLID SOLID}].
alpha
is the error rate used for confidence rings on the odds ratios. Use alpha=0; to suppress the confidence rings.
conf
The type of confidence rings, either 'Individual' (for each 2 x 2 table) or 'Joint' (for simultaneous confidence intervals covering all k 2 x 2 tables). [Default: conf='Individual'].
font
A character string specifying the font used. The default is Helvetica (font='hwpsl009') if a PostScript driver is being used, SWISS otherwise.
frame
the line style for the boxed frame (0=none).

Example

proc iml;
   %include iml(fourfold.sas);
   *-- Berkeley Admissions data;
   dim = {2 2 6};
   vnames = {'Admit?' 'Sex' 'Department'};
   lnames = {'Yes' 'No' ' '  ' '  ' '  ' ',
             'Male'  'Female' ' '  ' '  ' '  ' ',
             'A' 'B' 'C' 'D' 'E' 'F'};
   table = { 512  313, 89   19,
             353  207, 17    8,
             120  205, 202  391,
             138  279, 131  244,
              53  138, 94  299,
              22  351, 24  317};
   std='MARG';  /* IML4FOLD, fig 3 */
   alpha=.01;
   patterns={solid solid};
   htext = 2.4;
   filltype={hls hls};
   run fourfold(dim, table, vnames, lnames);

See also

agree Agreement chart for n x n table
mosaic Macro interface for mosaic displays
mosaics SAS/IML programs for mosaic displays
mosmat Macro interface for mosaic matrices
sieve Sieve diagrams for two-way tables