dataFrame.columns.stat — contingencyTable()

Description

The contingencyTable() method of the stat object computes a contingency table containing the observed frequencies for the selected categorical columns.

Signature

dataFrame.columns(...columnNames).stat.contingencyTable()
Scope
columns
Family
stat
Returns
table

Argument

...columnNames ( string[] )
The name of the columns from which to compute a contingency table.

Returns

table (array)
A two-dimensional table containing the observed frequencies for each category combination, including row and column totals.

Example :

          A1    A2    A3   TOTAL
B1        12     8     5      25
B2         7    14     4      25
B3         3     6    11      20
TOTAL     22    28    20      70

Notes

  • The method requires exactly two selected columns.
  • Categories from the first selected column are displayed as columns.
  • Categories from the second selected column are displayed as rows.
  • The last column contains row totals.
  • The last row contains column totals.
  • The bottom-right cell contains the grand total.
  • Each cell contains the observed frequency for a category combination.

Example

// compute a contingency table from 2 columns of the dataFrame
var table = dataFrame.columns('groupA', 'groupB').stat.contingencyTable();

// display the contingency table
notebook.output(table);