Package 'eikosograms'

Title: The Picture of Probability
Description: An eikosogram (ancient Greek for probability picture) divides the unit square into rectangular regions whose areas, sides, and widths, represent various probabilities associated with the values of one or more categorical variates. Rectangle areas are joint probabilities, widths are always marginal (though possibly joint margins, i.e. marginal joint distributions of two or more variates), and heights of rectangles are always conditional probabilities. Eikosograms embed the rules of probability and are useful for introducing elementary probability theory, including axioms, marginal, conditional, and joint probabilities, and their relationships (including Bayes theorem as a completely trivial consequence). They are markedly superior to Venn diagrams for this purpose, especially in distinguishing probabilistic independence, mutually exclusive events, coincident events, and associations. They also are useful for identifying and understanding conditional independence structure. As data analysis tools, eikosograms display categorical data in a manner similar to Mosaic plots, especially when only two variates are involved (the only case in which they are essentially identical, though eikosograms purposely disallow spacing between rectangles). Unlike Mosaic plots, eikosograms do not alternate axes as each new categorical variate (beyond two) is introduced. Instead, only one categorical variate, designated the "response", presents on the vertical axis and all others, designated the "conditioning" variates, appear on the horizontal. In this way, conditional probability appears only as height and marginal probabilities as widths. The eikosogram is therefore much better suited to a response model analysis (e.g. logistic model) than is a Mosaic plot. Mosaic plots are better suited to log-linear style modelling as in discrete multivariate analysis. Of course, eikosograms are also suited to discrete multivariate analysis with each variate in turn appearing as the response. This makes it better suited than Mosaic plots to discrete graphical models based on conditional independence graphs (i.e. "Bayesian Networks" or "BayesNets"). The eikosogram and its superiority to Venn diagrams in teaching probability is described in W.H. Cherry and R.W. Oldford (2003) <https://math.uwaterloo.ca/~rwoldfor/papers/eikosograms/paper.pdf>, its value in exploring conditional independence structure and relation to graphical and log-linear models is described in R.W. Oldford (2003) <https://math.uwaterloo.ca/~rwoldfor/papers/eikosograms/independence/paper.pdf>, and a number of problems, puzzles, and paradoxes that are easily explained with eikosograms are given in R.W. Oldford (2003) <https://math.uwaterloo.ca/~rwoldfor/papers/eikosograms/examples/paper.pdf>.
Authors: Wayne Oldford [aut, cre], Erle Holgersen [aut], Ben Lafreniere [aut], Tianlu Zhu [aut]
Maintainer: Wayne Oldford <[email protected]>
License: GPL-3
Version: 0.1.1.9000
Built: 2025-02-12 05:26:19 UTC
Source: https://github.com/rwoldford/eikosograms

Help Index


Generic method for creating an eikosogram

Description

Generic method for creating an eikosogram

Usage

eikos(y, x = NULL, data = NULL, marginalize = NULL, main = "",
  main_size = 16, ylabs = TRUE, ylab_rot = 0, yname_size = 12,
  yvals_size = 12, yaxs = TRUE, yprobs = NULL, yprobs_size = 8,
  xlabs = TRUE, xlab_rot = 0, xname_size = 12, xvals_size = 12,
  xaxs = TRUE, xprobs = NULL, xprobs_size = 8,
  vertical_xprobs = TRUE, ispace = list(bottom = 8, left = 2, top = 2,
  right = 5), legend = FALSE, col = NULL, bottomcol = "steelblue",
  topcol = "snow2", lcol = "black", draw = TRUE, newpage = TRUE,
  lock_aspect = TRUE)

Arguments

y

Either the name of a variable in the data set (eikos.default), or a formula of such variables (eikos.formula).

x

name(s) of any conditional variable(s) (horizontal axis). Should be null if formula given.

data

data frame or table

marginalize

variable(s) to marginalize on, or NULL if none. Marginalized variables still appear in plot.

main

title of plot

main_size

font size of title (in points)

ylabs

logical, whether y labels should appear or not.

ylab_rot

rotation of y labels

yname_size

font size of vertical axis names (in points)

yvals_size

font size of labels for values of y variable (in points)

yaxs

logical, whether y axis should appear or not.

yprobs

probabilities to be shown on y-axis. NULL if they should be calculated from the data.

yprobs_size

font size of labels for horizontal probabilities (in points)

xlabs

logical, whether x labels should appear or not.

xlab_rot

rotation of x labels

xname_size

font size of horizontal axis names (in points)

xvals_size

font size of labels for values of x variables (in points)

xaxs

logical, whether x axis should appear or not.

xprobs

probabilities to be shown on x-axis. NULL if they should be calculated from the data.

xprobs_size

font size of labels for horizontal probabilities (in points)

vertical_xprobs

logical, whether probabilities on x axis should be rotated vertically.

ispace

list of four items (bottom, left, top, right) indicating the margins separating the text around the diagram. Each value is a positive integer giving a measure in "points".

legend

logical, whether to include legend

col

a vector of colours to match the response values. If NULL (the default), the colours are constructed as a smooth transition from 'bottomcol' to 'topcol' via 'grDevices::colorRampPalette

bottomcol

bottom colour

topcol

top colour

lcol

colour of lines

draw

logical, whether to draw eikosogram.

newpage

logical, whether to draw on a newpage.

lock_aspect

logical, whether to force entire plot to 1:1 aspect ratio.

See Also

eikos.default

eikos.formula

Examples

eikos("Hair", "Eye", data=HairEyeColor, legend = TRUE)
eikos(gear ~ cyl, data = mtcars)
eikos(Admit ~  Gender + Dept, data = UCBAdmissions,  
      yaxs = FALSE, xaxs = FALSE, 
      lock_aspect = FALSE, 
      xlab_rot = 90, xvals_size = 8,
      ispace = list(bottom = 15))

Create eikosogram data frame

Description

Eikos helper function used to convert data.

Usage

eikos_data(y, x, data, marginalize = NULL)

Arguments

y

response variable.

x

conditional variables.

data

data frame or table to be converted.

marginalize

name of variable to marginalize on, NULL if none.


Create eikosogram legend

Description

Eikos helper function used to create legend.

Usage

eikos_legend(labels, title = NULL, yname_size = 12, yvals_size = 12,
  col, margin = unit(2, "points"), lcol = "black")

Arguments

labels

labels to be included in legend

title

if non-NULL a string to give as the legend title

yname_size

font size of vertical axis names (in points)

yvals_size

font size of labels for values of y variable (in points)

col

colours od

margin

unit specifying margin between legend entries

lcol

line colour


eikos helper function. Returns grob with x axis labels.

Description

eikos helper function. Returns grob with x axis labels.

Usage

eikos_x_labels(x, data, margin = unit(10, "points"), xname_size = 12,
  xvals_size = 10, lab_rot = 0)

Arguments

x

vector of conditional variables

data

data frame from eikos_data.

margin

unit specifying margin

xname_size

font size for x axis variable names (in points)

xvals_size

font size of labels for values of x variables (in points)

lab_rot

integer indicating the rotation of the label, default is horizontal

Value

gList with x labels and x-axis names as grob frames.


Create grob with eikosogram x-axis probabilities

Description

Creates x axis grob to be placed on eikosogram. Called by eikos functions.

Usage

eikos_x_probs(data, xprobs = NULL, xprobs_size = 8, margin = unit(2,
  "points"), rotate = TRUE)

Arguments

data

data frame from eikos_data object

xprobs

vector of probabilities to be shown. NULL if they should be calculated from the data.

xprobs_size

font size of labels for horizontal probabilities (in points)

margin

unit specifying margin between y axis and eikosogram

rotate

logical, whether probabilities should be rotated vertically.

Value

textGrob with x-axis probabilities.


eikos helper function. Returns grob with y axis labels.

Description

eikos helper function. Returns grob with y axis labels.

Usage

eikos_y_labels(y, data, margin = unit(2, "points"), yname_size = 12,
  yvals_size = 10, lab_rot = 0)

Arguments

y

response variable

data

data frame from eikos_data.

margin

unit specifying margin

yname_size

font size for y axis variable names (in points)

yvals_size

font size of labels for values of y variable (in points)

lab_rot

integer indicating the rotation of the label, default is horizontal

Value

gList with x labels and x-axis names as grob frames.

grobFrame with response variable labels and axis text


Create grob with eikosogram y-axis probabilities

Description

Creates y axis grob to be placed on eikosogram. Called by eikos functions.

Usage

eikos_y_probs(data, yprobs, yprobs_size = 8, margin = unit(2,
  "points"))

Arguments

data

data frame from eikos_data object

yprobs

vector of probabilities to be shown. NULL if they should be calculated from the data.

yprobs_size

font size of labels for horizontal probabilities (in points)

margin

unit specifying margin between y axis and eikosogram

Value

textGrob with y-axis probabilities.


Create a new eikosogram

Description

Return a grid graphic object (grob) and draw an eikosogram if draw = TRUE.

Usage

## Default S3 method:
eikos(y, x = NULL, data = NULL, marginalize = NULL,
  main = "", main_size = 16, ylabs = TRUE, ylab_rot = 0,
  yname_size = 12, yvals_size = 12, yaxs = TRUE, yprobs = NULL,
  yprobs_size = 8, xlabs = TRUE, xlab_rot = 0, xname_size = 12,
  xvals_size = 12, xaxs = TRUE, xprobs = NULL, xprobs_size = 8,
  vertical_xprobs = TRUE, ispace = list(bottom = 8, left = 2, top = 2,
  right = 5), legend = FALSE, col = NULL, bottomcol = "steelblue",
  topcol = "snow2", lcol = "black", draw = TRUE, newpage = TRUE,
  lock_aspect = TRUE)

Arguments

y

Either the name of a variable in the data set (eikos.default), or a formula of such variables (eikos.formula).

x

name(s) of any conditional variable(s) (horizontal axis). Should be null if formula given.

data

data frame or table

marginalize

variable(s) to marginalize on, or NULL if none. Marginalized variables still appear in plot.

main

title of plot

main_size

font size of title (in points)

ylabs

logical, whether y labels should appear or not.

ylab_rot

rotation of y labels

yname_size

font size of vertical axis names (in points)

yvals_size

font size of labels for values of y variable (in points)

yaxs

logical, whether y axis should appear or not.

yprobs

probabilities to be shown on y-axis. NULL if they should be calculated from the data.

yprobs_size

font size of labels for horizontal probabilities (in points)

xlabs

logical, whether x labels should appear or not.

xlab_rot

rotation of x labels

xname_size

font size of horizontal axis names (in points)

xvals_size

font size of labels for values of x variables (in points)

xaxs

logical, whether x axis should appear or not.

xprobs

probabilities to be shown on x-axis. NULL if they should be calculated from the data.

xprobs_size

font size of labels for horizontal probabilities (in points)

vertical_xprobs

logical, whether probabilities on x axis should be rotated vertically.

ispace

list of four items (bottom, left, top, right) indicating the margins separating the text around the diagram. Each value is a positive integer giving a measure in "points".

legend

logical, whether to include legend

col

a vector of colours to match the response values. If NULL (the default), the colours are constructed as a smooth transition from 'bottomcol' to 'topcol' via 'grDevices::colorRampPalette

bottomcol

bottom colour

topcol

top colour

lcol

colour of lines

draw

logical, whether to draw eikosogram.

newpage

logical, whether to draw on a newpage.

lock_aspect

logical, whether to force entire plot to 1:1 aspect ratio.

Examples

eikos("Hair", "Eye", data=HairEyeColor, legend = TRUE)
eikos("Hair", "Eye", data=HairEyeColor, 
      legend = TRUE, ylabs = FALSE, 
      yname_size = 16, yvals_size = 8)
eikos("Hair", "Eye", data=HairEyeColor, 
      legend = TRUE, ylabs = FALSE, 
      yprobs = seq(0.2, 1, .2))
eikos("Eye", "Hair", data=HairEyeColor, yprobs = seq(0,1,0.25),
      yname_size = 20, xname_size = 20,
      col = c("sienna4", "steelblue", "darkkhaki", "springgreen3"),
      lcol = "grey10",
      lock_aspect = FALSE)

Draw eikosogram using a formula to identify response and conditioning variates

Description

Draw eikosogram using a formula to identify response and conditioning variates

Usage

## S3 method for class 'formula'
eikos(y, x = NULL, data = NULL, marginalize = NULL,
  main = "", main_size = 16, ylabs = TRUE, ylab_rot = 0,
  yname_size = 12, yvals_size = 12, yaxs = TRUE, yprobs = NULL,
  yprobs_size = 8, xlabs = TRUE, xlab_rot = 0, xname_size = 12,
  xvals_size = 12, xaxs = TRUE, xprobs = NULL, xprobs_size = 8,
  vertical_xprobs = TRUE, ispace = list(bottom = 8, left = 2, top = 2,
  right = 5), legend = FALSE, col = NULL, bottomcol = "steelblue",
  topcol = "snow2", lcol = "black", draw = TRUE, newpage = TRUE,
  lock_aspect = TRUE)

Arguments

y

Either the name of a variable in the data set (eikos.default), or a formula of such variables (eikos.formula).

x

name(s) of any conditional variable(s) (horizontal axis). Should be null if formula given.

data

data frame or table

marginalize

variable(s) to marginalize on, or NULL if none. Marginalized variables still appear in plot.

main

title of plot

main_size

font size of title (in points)

ylabs

logical, whether y labels should appear or not.

ylab_rot

rotation of y labels

yname_size

font size of vertical axis names (in points)

yvals_size

font size of labels for values of y variable (in points)

yaxs

logical, whether y axis should appear or not.

yprobs

probabilities to be shown on y-axis. NULL if they should be calculated from the data.

yprobs_size

font size of labels for horizontal probabilities (in points)

xlabs

logical, whether x labels should appear or not.

xlab_rot

rotation of x labels

xname_size

font size of horizontal axis names (in points)

xvals_size

font size of labels for values of x variables (in points)

xaxs

logical, whether x axis should appear or not.

xprobs

probabilities to be shown on x-axis. NULL if they should be calculated from the data.

xprobs_size

font size of labels for horizontal probabilities (in points)

vertical_xprobs

logical, whether probabilities on x axis should be rotated vertically.

ispace

list of four items (bottom, left, top, right) indicating the margins separating the text around the diagram. Each value is a positive integer giving a measure in "points".

legend

logical, whether to include legend

col

a vector of colours to match the response values. If NULL (the default), the colours are constructed as a smooth transition from 'bottomcol' to 'topcol' via 'grDevices::colorRampPalette

bottomcol

bottom colour

topcol

top colour

lcol

colour of lines

draw

logical, whether to draw eikosogram.

newpage

logical, whether to draw on a newpage.

lock_aspect

logical, whether to force entire plot to 1:1 aspect ratio.

Examples

eikos(Eye ~ Hair + Sex, data=HairEyeColor)
eikos(Hair ~ ., data=HairEyeColor, 
      yaxs = FALSE, ylabs = FALSE,
      legend = TRUE, 
      col = c("black", "sienna4", 
              "orangered", "lightgoldenrod" ))
eikos(Hair ~ ., data=HairEyeColor, xlab_rot = 30,
      yprobs = seq(0.1, 1, 0.1),
      yvals_size = 10,
      xvals_size = 8,
      ispace = list(bottom = 10),
      bottomcol = "grey30", topcol = "grey70",
      lcol = "white")
eikos(Hair ~ ., data=HairEyeColor, xlab_rot = 30,
      marginalize = "Eye",
      yvals_size = 10,
      xvals_size = 8,
      ispace = list(bottom = 10),
      bottomcol = "grey30", topcol = "grey70",
      lcol = "white")
eikos(Hair ~ ., data=HairEyeColor, xlab_rot = 30,
      marginalize = c("Eye", "Sex"),
      yvals_size = 10,
      xvals_size = 8,
      ispace = list(bottom = 10),
      bottomcol = "grey30", topcol = "grey70",
      lcol = "white")