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
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | "Joint probability table" | Title bar text. |
| rows | string[] | ["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. |
| cols | string[] | ["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. |
| units | string | inferred (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. |
| rowVariable | string | from the labels ("x=0" gives X), else none | Name of the row variable, e.g. "X" or "Smoking"; used in the corner cell, toggle labels and formulas. |
| colVariable | string | from the labels ("y=0" gives Y), else none | Name of the column variable. |
| rowValues | number[] | parsed from the row labels | Numeric values of the row variable, for covariance and events, when the labels are not numbers. |
| colValues | number[] | parsed from the column labels | Numeric values of the column variable, for conditional means/variances, covariance and events. |
| display | string | "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" | label | none | Initial 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. |
| chart | string | "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. |
| event | string | none | Event 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. |
| markCells | boolean | true | Learner can click cells to add them to (or remove them from) the event A and see P(A) as a sum. |
| editable | boolean | true | Show an Edit switch: type new entries and add or remove rows and columns. |
| format | string | "decimal" | decimal, or fraction (exact small fractions such as 1/3 where they exist, decimals otherwise). |
| digits | number | 3 | Decimals for probabilities and statistics (0 to 6). |
| showIndependence | boolean | false | Independence 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. |
| showChiSquared | boolean | false | Chi-squared statistic, df, p-value and smallest expected count (counts only); in the expected display each cell also shows its contribution. |
| simulate | boolean | false | Simulate 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. |
| simulations | number | 0 | Tables 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. |
| fixedMargins | string | "total" | What the simulation holds fixed: total (one sample; test of independence), rows (each row total; homogeneity with groups in rows) or columns. |
| seed | number | string | 1 | Seed of the simulation's random stream. |
| showConditionalMeans | boolean | false | Column E[Y | X = x] for each row, with E[Y] in the bottom row (needs numeric column values). |
| showConditionalVariances | boolean | false | Column Var(Y | X = x) for each row, with Var(Y) in the bottom row. |
| showTotalExpectation | boolean | false | Law of total expectation written out: E[Y] = sum of E[Y | X = x] p_X(x) with the table's numbers. |
| showVarianceDecomposition | boolean | false | Law of total variance: Var(Y) = E[Var(Y | X)] + Var(E[Y | X]) with an explained/unexplained bar and eta squared. |
| showCovariance | boolean | false | E[X], E[Y], E[XY], Cov(X, Y) = E[XY] - E[X]E[Y] and the correlation (needs numeric row and column values). |
| showEntropies | boolean | false | H(X), H(Y), H(X,Y), H(Y | X), H(X | Y) and I(X;Y) in bits. |
| controls | string[] | all controls shown | Ids 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. |
PreviousNext