Joint probability table

An editable two-way table of counts or probabilities with its marginals. Learners click a row or column label to condition on it (row/column profiles as 100% bars or a mosaic), click cells to build an event and read off its probability, compare the table with the product of its margins, and optionally see chi-squared, simulated tables under independence, conditional means and variances, covariance or entropies.

Used in: Introduction to Probability Theory, Introduction to Statistics

Props

PropTypeDefaultDescription
titlestring"Joint probability table"Title bar text.
rowsstring[]["x=0", "x=1", "x=2"] (x=0, x=1, ... for other sizes)Row category labels ($...$ TeX allowed). Labels like "x=2" also give the row's numeric value.
colsstring[]["y=0", "y=1"] (y=0, y=1, ... for other sizes)Column category labels, as for rows.
cells(number | string)[][][[0.1, 0.2], [0.2, 0.1], [0.3, 0.1]]Rows x columns of non-negative counts or probabilities (up to 10 x 10). Strings may be fractions such as "1/36". Rows/cols without cells start from a table of 1s.
unitsstringinferred (probabilities if the entries sum to 1, else counts)counts (totals, expected counts, chi-squared) or probabilities (marginals, product of margins). Probabilities that do not sum to 1 are rescaled with a note.
rowVariablestringfrom the labels ("x=0" gives X), else noneName of the row variable, e.g. "X" or "Smoking"; used in the corner cell, toggle labels and formulas.
colVariablestringfrom the labels ("y=0" gives Y), else noneName of the column variable.
rowValuesnumber[]parsed from the row labelsNumeric values of the row variable, for covariance and events, when the labels are not numbers.
colValuesnumber[]parsed from the column labelsNumeric values of the column variable, for conditional means/variances, covariance and events.
displaystring"values" (or row/column when conditionOn is set)What the cells show at first: values (counts or joint probabilities), joint (count / total; counts only), row (divided by the row total), column (divided by the column total), expected (product of margins / expected counts, with the observed value below). The learner can switch.
conditionOn{row: label} | {col: label} | "rows" | "columns" | labelnoneInitial conditioning: one row or column (by label or 0-based index) is selected and its conditional distribution shown with a/b = value readouts; "rows" / "columns" shows all profiles with none selected.
chartstring"bars"Profile chart beside the table: bars (one 100% bar per category plus the overall distribution), mosaic (bar thickness = marginal, tile area = joint) or none. The learner can switch between bars and mosaic.
eventstringnoneEvent on (x, y) to mark at first, e.g. "x + y <= 1", "x > y", "x == 1 or y == 1", "x >= 1 and y == 0". Needs numeric row/column values.
markCellsbooleantrueLearner can click cells to add them to (or remove them from) the event A and see P(A) as a sum.
editablebooleantrueShow an Edit switch: type new entries and add or remove rows and columns.
formatstring"decimal"decimal, or fraction (exact small fractions such as 1/3 where they exist, decimals otherwise).
digitsnumber3Decimals for probabilities and statistics (0 to 6).
showIndependencebooleanfalseIndependence check: compares every cell with the product of its margins (or R C / n), names the largest gap, flags a non-product support, and offers a Make independent button.
showChiSquaredbooleanfalseChi-squared statistic, df, p-value and smallest expected count (counts only); in the expected display each cell also shows its contribution.
simulatebooleanfalseSimulate 1 / 100 / 1000 tables under independence (counts only): histogram of simulated chi-squared with the chi-squared density and the observed value, and the simulated p-value.
simulationsnumber0Tables simulated on load (0 to 5000, from the seed) when simulate is on, so the histogram starts filled; the learner adds more with the buttons.
fixedMarginsstring"total"What the simulation holds fixed: total (one sample; test of independence), rows (each row total; homogeneity with groups in rows) or columns.
seednumber | string1Seed of the simulation's random stream.
showConditionalMeansbooleanfalseColumn E[Y | X = x] for each row, with E[Y] in the bottom row (needs numeric column values).
showConditionalVariancesbooleanfalseColumn Var(Y | X = x) for each row, with Var(Y) in the bottom row.
showTotalExpectationbooleanfalseLaw of total expectation written out: E[Y] = sum of E[Y | X = x] p_X(x) with the table's numbers.
showVarianceDecompositionbooleanfalseLaw of total variance: Var(Y) = E[Var(Y | X)] + Var(E[Y | X]) with an explained/unexplained bar and eta squared.
showCovariancebooleanfalseE[X], E[Y], E[XY], Cov(X, Y) = E[XY] - E[X]E[Y] and the correlation (needs numeric row and column values).
showEntropiesbooleanfalseH(X), H(Y), H(X,Y), H(Y | X), H(X | Y) and I(X;Y) in bits.
controlsstring[]all controls shownIds of the hideable controls and text to show (see the controls registry, e.g. display.expected, label.marginal, readout.probability-notation, readout.correlation). Core controls always show. Absent = everything. Fitted per page by tooling (component_scopes.py fit-nodes), not by hand.