Mosaic Analysis
Context
BayesiaLab’s Mosaic Analysis can produce high-dimensional Mosaic Plots to visualize marginal and conditional distributions of nodes in a Bayesian network. Mosaic Analysis is a useful tool for creating a data overview and highlighting dependencies between nodes, or the lack thereof. The Mosaic Analysis can also display Standardized Pearson Residuals, which are computed for all cells in the plot. For easy comparison, all cells are color-coded using Standardized Pearson Residuals.
Usage
To illustrate the basic display and layout options of the Mosaic Analysis, we use an arbitrary Bayesian network with four nodes, through , which you can download here:
Switch to Menus > View > Validation Mode, then select one or more nodes. Then, go to Menus > Analysis > Visual > Overall > Mosaic. A new window opens up offering you a number of settings:

Variables
The nodes we originally selected on the Graph Panel are now shown in the Variables table:
Note that we refer to both Nodes and Variables here. This is because we can analyze the probabilities on the basis of the states of the Nodes in the network or, if available, on the data recorded in the original Variables.
You can reassign the nodes to different positions by using the Up and Down buttons.
Options
Under Options, you can configure the overall layout of the Mosaic Plot given the number of available nodes.
Nodes | ![]() | ![]() | ![]() |
|---|---|---|---|
1 | Loading SVG... | n/a | n/a |
| Loading SVG... |
|
|
2 | Loading SVG... | Loading SVG... | Loading SVG... |
| Loading SVG... | Loading SVG... | Loading SVG... |
3 | Loading SVG... | Loading SVG... | Loading SVG... |
| Loading SVG... | Loading SVG... | Loading SVG... |
4 | Loading SVG... | Loading SVG... | Loading SVG... |
| Loading SVG... | Loading SVG... | Loading SVG... |
Source
The Source panel at the bottom of the window allows you to choose the basis for generating the Mosaic Plot.

One of the key features of the Mosaic Analysis is the ability to generate statistical measures for augmenting the visual presentation.
This is possible for Bayesian networks with and without an associated dataset:
- If a dataset is associated with your network, you can choose the Source, i.e., Data Set or Network.
- Data Set: the Standardized Pearson Residual is computed with the associated dataset.
- If there are Hidden Nodes in the network, i.e., nodes without any corresponding data, the Mosaic Analysis defaults to Network as a source.
- If the associated dataset contains Learning Set/Test Set split, you can select either subset or all observations.
- Network: BayesiaLab uses the given network to generate a dataset from which the Standardized Pearson Residual can be computed.
- In the Prior Samples field, you need to specify the number of observations or samples to be generated.
- If no dataset is associated with your network, only the Network option is available as a Source for the Mosaic Analysis.
Beyond the Mosaic Analysis settings that we explained in the above section, we illustrate the complete Mosaic Analysis workflow in the following example.
Usage example
To explain the Mosaic Analysis workflow in more detail, we use a Bayesian network that represents the relationship between , , and . You can download the network here:
For this analysis, switch to Menus > View > Validation Mode and select all three nodes, i.e., , , and . Then, go to Menus > Analysis > Visual > Overall > Mosaic.
The working copy expands the original 32 frequency-weighted rows into 592 individual records with the same exact joint distribution. This preserves the book’s interpretation of populations and statistical sample size. Original source files are retained.
Configuration
The configuration window opens.

The above settings specify that:
- is the first horizontal variable (Horizontal 0 or H0).
- is the first vertical variable (Vertical 0 or V0)
- is the second horizontal variable (Horizontal 1 or H1)
Furthermore, the Options panel includes a Reference Engine section, which only applies to analyses with precisely 3 variables. However, we defer the discussion and will include it in a dedicated section about the Standardized Pearson Residual.
Mosaic Plot
Upon clicking OK, the Mosaic window opens up with a colorful mosaic.
The bar at the very bottom of the plot represents the marginal distribution of . The length of each section is proportional to the marginal probability of the corresponding state. Given the near 50/50 split of male and female subjects in the dataset, the red and green bars have almost the same length.
The bar closest to the mosaic represents the marginal distribution of . Here, the differences in marginal probabilities are more prominent.
The vertical bar to the left of the mosaic represents the marginal distribution of . Its native vector excerpt below is rotated for horizontal reading.
The size or area of each cell in the main area of the Mosaic Plot is proportional to the Joint Probability of the states that correspond to that cell in the plot area, i.e., , which is in our example .
Furthermore, the width of each cell is proportional to the conditional probability , i.e., .
Finally, the height of each cell is proportional to , i.e., .
Tooltip
If Tooltips do not appear, enable Menus > View > Show Information While Hovering. The Hide Information toolbar setting can remain enabled.
As there are no labels on the cells, you can bring up all cell-specific information in Tooltips. Whenever you hover over any of the cells with your cursor, a Tooltip appears, like the one below:

For instance, the cell identified by the Tooltip in the following screenshot represents the Joint Probability . Note that, in this context, the comma (“,”) represents the conjunction “and”.

Each Tooltip includes the following items:
-
The states that correspond to the Joint Probability, e.g., , , , which is the cell in the upper left-hand corner of the plot.
-
The value of the Joint Probability, . Given the size constraint of the Tooltip, this expression is shown in abbreviated form, i.e., .
-
The Conditional Probability , i.e., the probability that is given that is and is . Note that the vertical bar “” means “given that.”
-
The size of the corresponding population in the dataset, i.e., Population = 7. So, 7 out of 592 cases are females, have blue eyes and red hair.
- In this example, we generated the Mosaic Plot from an attached dataset.
- However, we could have produced the plot on the basis of the network only, using simulated data. For instance, had we created 1,000 Prior Samples, the corresponding blue/red/female population would be 11.8, i.e., 1.18% of the overall population of 1,000 Prior Samples.
-
The D-Value shown in the Tooltip represents the Standardized Pearson Residual of the cell. We discuss the D-Value and Standardized Pearson Residual in the following section.
Independence tests & Standardized Pearson Residual
The Mosaic Analysis provides test statistics on two levels:
-
Overall Statistics: With the Mosaic Plot, BayesiaLab performs an independence test -Test or G-Test for all variables in the analysis.
-
You can specify which test to use under Menus > Window > Preferences > Tools > Statistical Tools.
-
The selected test statistic is shown at the top of the Mosaic window, including the degrees of freedom and the p-value.
Loading SVG... -
The displayed p-value of 0.00% is rounded, rather than exactly zero. The test rejects the null hypothesis of mutual independence at conventional significance levels.
-
For this worked example, select χ² in Independence Test under Menus > Window > Preferences > Tools > Statistical Tools. The generic layout illustrations above use G.
-
-
Cell-Specific Statistic: For each cell in the Mosaic Plot, BayesiaLab computes the Standardized Pearson Residual, denoted .
-
The Standardized Pearson Residual captures each cell’s departure from its expected value and, thus, quantifies any potential over- or under-representation of a particular cell in the Mosaic Plot relative to the Null-Hypothesis.
-
It is defined as follows:
where and represent the observed and expected values of cell .
-
The value of is included in the information provided in the Tooltip.
-
Additionally, can be specifically visualized in an alternate view of the Mosaic Plot, i.e., the Residuals Plot.
-
Residuals Plot
To switch to the Residuals Plot, check the Show Residuals checkbox at the bottom of the Mosaic window. Now the color-coding of the cells corresponds to the Standardized Pearson Residual ():
: very significant over-representation | |
: significant over-representation | |
: no significant over-representation | |
: no significant under-representation | |
: significant under-representation | |
: very significant under-representation | |
Denotes the absence of observations in the dataset or the simulated data. |
A residual of means that the observed and expected values are equal. The white swatch denotes the absence of observations, rather than a residual of zero.
In the above Residuals Plot, the most notable over-representation is for with . In other words, for females, there is a significant positive correlation between blue eyes and blond hair. The adjacent cell, i.e., , is an example of very significant under-representation with . This means that, for females, there is a significant negative correlation between brown eyes and blond hair.
Null-hypothesis options for three-dimensional plots
For three-dimensional plots only, the Mosaic Analysis offers options that are not available in any other context. If you select three nodes to be included in the Mosaic Analysis, the configuration window offers an additional option:

Under Reference Engine, you can select between the three structures that represent the Null-Hypothesis:
- H0, H1, and V0 are all independent nodes, i.e., an unconnected network.
- H0 and H1 are dependent, while V0 is independent.
- H0 and H1 are dependent, plus H0 and V0 are dependent. H1 and V0 are conditionally independent.
With that, we can focus on investigating the relationships of specific variables. For instance, now that we have learned about the significant correlation between and , we can specifically test for the independence of . In the variables list, we move to position V0 and select the corresponding Reference Engine.

The Residual Plot shows the results:
We see that on the basis of the -Test, we cannot reject the Null-Hypothesis that is independent. However, values of -2.15 and 2.03 respectively suggest that, given blue eyes, blond hair is still under-represented among males and over-represented for females.
On this basis, we can revisit the Null-Hypothesis and now speculate that is independent of conditional on . We arrange the variables accordingly in the Variables list.

Indeed, the Residual Plot appears to confirm our speculation:
We see that on the basis of the -Test, we cannot reject the Null-Hypothesis that and are independent conditional on . As indicated by the Tooltips, all values are now within the non-significant range.
Display options
At the bottom of the Mosaic window, there are additional options regarding the styling of the Mosaic Plot.
With the Resizable Chart option engaged, you can resize the Mosaic window and the Mosaic Plot itself will adjust automatically while maintaining the proportionality of probabilities and cell areas.
With the Resizable Chart option disabled, the Mosaic Plot will be of a fixed size. As a result, you may need to resize the window or use the scrollbars to see the entire plot.

The last option affects the size of the gaps between the cells in the plot:
- Automatic Gap
- Constant Gap: You can specify the gap width between the cells in pixels.
The following table compares the two gap options side-by-side.
Automatic Gap | Constant Gap |
|---|---|
Loading SVG... | Loading SVG... |


