paik: Paik-Agresti diagrams

paikR Documentation

Paik-Agresti diagrams

Description

Construct a Paik-Agresti diagram adapted and enhanced from the asbio::paik function.

Usage

paik(
  formula,
  data,
  counts,
  resp.lvl = 2,
  circle.mult = 1,
  xlab = NULL,
  ylab = NULL,
  leg.title = NULL,
  leg.loc = NULL,
  show.mname = TRUE,
  col = c("#1B9E77", "#D95F02", "#7570B3", "#E7298A", "#66A61E", "#E6AB02", "#A6761D",
    "#666666"),
  alpha = "66",
  marginal = TRUE,
  cex = 1,
  cex.cond = cex,
  cex.marg = cex,
  pch.cond = 19,
  pch.marg = 15,
  lwd = 2,
  lwd.marg = lwd,
  lwd.cond = lwd,
  lwd.circle = lwd,
  raise.prop = 0.03,
  ...
)

paik2(
  formula,
  data,
  counts,
  resp.lvl = 2,
  circle.mult = 1,
  xlab = NULL,
  ylab = NULL,
  leg.title = NULL,
  leg.loc = NULL,
  mtext = "Overall proportion",
  col = c("#1B9E77", "#D95F02", "#7570B3", "#E7298A", "#66A61E", "#E6AB02", "#A6761D",
    "#666666"),
  alpha = "66",
  marginal = TRUE,
  cex = 1,
  cex.cond = cex,
  cex.marg = cex,
  pch.cond = 19,
  pch.marg = 15,
  lwd = 2,
  lwd.marg = lwd,
  lwd.cond = lwd,
  lwd.circle = lwd,
  raise.prop = 0.03,
  circle.factor = 0.2,
  ylim,
  ...
)

Arguments

formula

A two sided formula, e.g. Y ~ X1 + X2, with cross-classified variables that will be treated as categorical variables. The levels of the first explanatory variable, X1 are displayed along the x-axis and the second explanatory variable, X2, is used as the conditioning variable whose levels are distinguished in the graph with different colors. Interactions and nested terms are not allowed.

data

data.frame containing variables in formula. If rows of the the data frame should represent more than one observation, a variable named 'Freq' must record the frequency of each row, or the frequencies must be given through the 'counts' parameter below.

counts

A vector of counts for the associated categorical variables in formula. The variable 'Freq' is used if it exists in the data frame, data

resp.lvl

The level in Y of primary interest. See example below.

circle.mult

Multiplier for circle radii in the diagram.

xlab

X-axis label. By default this is defined as the categories in the first explanatory variable, X1.

ylab

Y-axis label. By default these will be proportions with respect to the specified level of interest in the response.

leg.title

Legend title. By default the conditioning variable name.

leg.loc

Legend location. A legend location keyword; "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" or "center".

show.mname

Logical, indicating whether or not the words "Overall proportion" should be printed in the graph above the dotted line indicating marginal proportions.

col

list of colors for conditional levels. Default: the 8 colours of the 'Dark2' palette of RColorBrewer.

alpha

transparency for circles expressed in hexadecimal, e.g. 'AA' or 'FF' for no transparency. Default: '66'

marginal

logical, show marginal relationship, default: TRUE

cex,

cex.cond, cex.marg cex for points, default: 1, default for cex.cond and cex.marg is cex

pch.cond

pch for conditional points, default 19

pch.marg

pch for marginal points, default 15

lwd

lwd for line segments, default: 2

lwd.marg

lwd for marginal (overall) line segments. Default: lwd

lwd.cond

lwd for conditional line segments. Default: lwd

raise.prop

proportion of vertical height of plot by which to raise the "Overall Proportion" label. Default: 0.03

...

Additional arguments from plot. Especially useful to provide ylim if needed.

Functions

  • paik2(): version for numerical Y value

Author(s)

Ken Aho, modified by Georges Monette based on an idea by Fan Zhu

References

Agresti, A. (2012) Categorical Data Analysis, 3rd edition. New York. Wiley. Paik M. (1985) A graphical representation of a three-way contingency table: Simpson's paradox and correlation. American Statistician 39:53-54.

Examples

data(death.penalty) # from Agresti 2012 
print(death.penalty)
op <- par(mfrow=c(1,2), mar=c(4,4,0.1,0.1))
paik(verdict ~ d.race + v.race, 
   counts = death.penalty$count,
   data = death.penalty, 
   leg.title = "Victims' race", xlab = "Defendants' race", 
   ylab = "Proportion receiving death penalty")
par(mar=c(4,2,0,2))
paik(verdict ~ v.race + d.race, counts = death.penalty$count, data = death.penalty, 
     xlab = "Victims' race", leg.title = "Defendants' race",leg.loc="topleft", 
     ylab = "", yaxt = "n")
paik(am ~ gear + carb, mtcars)
par(op)
dd <- death.penalty  
dd$Freq <- dd$count
dd$ver <- as.numeric(dd$verdict == 'Y')
paik2(ver ~ d.race + v.race, dd, cex = 2, circle.factor = .2)  

d <- mtcars
paik2(mpg ~ cyl + gear, d, cex = 3)  

gmonette/spida2 documentation built on Aug. 20, 2023, 7:21 p.m.