Skip to Content

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, N1\mathit{N1} through N4\mathit{N4}, which you can download here:

GenericNetwork.xbl
XBL

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:

Four-variable Mosaic settings
Click to Zoom

Variables

The nodes we originally selected on the Graph Panel are now shown in the Variables table:

Loading SVG...
Click to Zoom

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

Vertical layout controls
Click to Zoom
Horizontal layout controls
Click to Zoom
Conditional layout controls
Click to Zoom

1

Loading SVG...
Click to Zoom

n/a

n/a

 

Loading SVG...
Click to Zoom

 

 

2

Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom

 

Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom

3

Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom

 

Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom

4

Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom

 

Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom
Loading SVG...
Click to Zoom

Source

The Source panel at the bottom of the window allows you to choose the basis for generating the Mosaic Plot.

Mosaic data source controls
Click to Zoom

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 Hair Color\mathit{Hair\ Color}, Eye Color\mathit{Eye\ Color}, and Sex\mathit{Sex}. You can download the network here:

HairColorEyeColorSex — 592 records (.XBL)
XBL

For this analysis, switch to Menus > View > Validation Mode and select all three nodes, i.e., Hair Color\mathit{Hair\ Color}, Eye Color\mathit{Eye\ Color}, and Sex\mathit{Sex}. 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.

Reference Engine — three native model choices
Click to Zoom

The above settings specify that:

  • Sex\mathit{Sex} is the first horizontal variable (Horizontal 0 or H0).
  • Hair Color\mathit{Hair\ Color} is the first vertical variable (Vertical 0 or V0)
  • Eye Color\mathit{Eye\ Color} 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.

Loading SVG...
Click to Zoom

The bar at the very bottom of the plot represents the marginal distribution of Sex\mathit{Sex}. 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.

Loading SVG...
Click to Zoom

The bar closest to the mosaic represents the marginal distribution of Eye Color\mathit{Eye\ Color}. Here, the differences in marginal probabilities are more prominent.

Loading SVG...
Click to Zoom

The vertical bar to the left of the mosaic represents the marginal distribution of Hair Color\mathit{Hair\ Color}. Its native vector excerpt below is rotated for horizontal reading.

Loading SVG...
Click to Zoom

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., P(H1,V0,H0)P(\mathrm{H1}, \mathrm{V0}, \mathrm{H0}), which is in our example P(Eye Color,Hair Color,Sex)P(\mathit{Eye\ Color}, \mathit{Hair\ Color}, \mathit{Sex}).

Loading SVG...
Click to Zoom

Furthermore, the width of each cell is proportional to the conditional probability P(H1∣V0,H0)P(\mathrm{H1} \mid \mathrm{V0}, \mathrm{H0}), i.e., P(Eye Color∣Hair Color,Sex)P(\mathit{Eye\ Color} \mid \mathit{Hair\ Color}, \mathit{Sex}).

Finally, the height of each cell is proportional to P(V0∣H0)P(\mathrm{V0} \mid \mathrm{H0}), i.e., P(Hair Color∣Sex)P(\mathit{Hair\ Color} \mid \mathit{Sex}).

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:

Blue eyes, red hair, female — native tooltip
Click to Zoom

For instance, the cell identified by the Tooltip in the following screenshot represents the Joint Probability P(Eye Color=Blue,Hair Color=Red,Sex=Female)P(\mathit{Eye\ Color}=\mathrm{Blue}, \mathit{Hair\ Color}=\mathrm{Red}, \mathit{Sex}=\mathrm{Female}). Note that, in this context, the comma (“,”) represents the conjunction “and”.

Seven-person tooltip in the complete Mosaic window
Click to Zoom

Each Tooltip includes the following items:

  • The states that correspond to the Joint Probability, e.g., Eye Color=Blue\mathit{Eye\ Color}=\mathrm{Blue}, Hair Color=Red\mathit{Hair\ Color}=\mathrm{Red}, Sex=Female\mathit{Sex}=\mathrm{Female}, which is the cell in the upper left-hand corner of the plot.

  • The value of the Joint Probability, P(Eye Color=Blue,Hair Color=Red,Sex=Female)=1.182%P(\mathit{Eye\ Color}=\mathrm{Blue}, \mathit{Hair\ Color}=\mathrm{Red}, \mathit{Sex}=\mathrm{Female}) = 1.182\%. Given the size constraint of the Tooltip, this expression is shown in abbreviated form, i.e., P(Eye Color=Blue,...)=1.182%P(\mathit{Eye\ Color}=\mathrm{Blue}, ...) = 1.182\%.

  • The Conditional Probability P(Eye Color=Blue∣Hair Color=Red,Sex=Female)=18.92%P(\mathit{Eye\ Color}=\mathrm{Blue} \mid \mathit{Hair\ Color}=\mathrm{Red}, \mathit{Sex}=\mathrm{Female}) = 18.92\%, i.e., the probability that Eye Color\mathit{Eye\ Color} is Blue\mathrm{Blue} given that Hair Color\mathit{Hair\ Color} is Red\mathrm{Red} and Sex\mathit{Sex} is Female\mathrm{Female}. Note that the vertical bar “∣\mid” 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 χ2\chi^2-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...
      Click to Zoom
    • 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 DD.

    • 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:

      D=χ=Oi−EiEiD = \chi = \frac{{{O_i} - {E_i}}}{{\sqrt {{E_i}} }}

      where OO and EE represent the observed and expected values of cell ii.

    • The value of DD is included in the information provided in the Tooltip.

    • Additionally, DD 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 (DD):

Loading SVG...
Click to Zoom

D>4D \gt 4: very significant over-representation

2<D≤42 < D \le 4: significant over-representation

0<D≤20 < D \le 2: no significant over-representation

−2≤D<0-2 \le D < 0: no significant under-representation

−4≤D<−2-4 \le D < -2: significant under-representation

D<−4D \lt -4: very significant under-representation

Denotes the absence of observations in the dataset or the simulated data.

A residual of D=0D=0 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 P(Eye Color=Blue,Hair Color=Blond,Sex=Female)P(\mathit{Eye\ Color}=\mathrm{Blue}, \mathit{Hair\ Color}=\mathrm{Blond}, \mathit{Sex}=\mathrm{Female}) with D=8.02D=8.02. In other words, for females, there is a significant positive correlation between blue eyes and blond hair. The adjacent cell, i.e., P(Eye Color=Brown,Hair Color=Blond,Sex=Female)P(\mathit{Eye\ Color}=\mathrm{Brown}, \mathit{Hair\ Color}=\mathrm{Blond}, \mathit{Sex}=\mathrm{Female}), is an example of very significant under-representation with D≈−4.19D\approx -4.19. 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:

Reference Engine — three native model choices
Click to Zoom

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 Eye Color\mathit{Eye\ Color} and Hair Color\mathit{Hair\ Color}, we can specifically test for the independence of Sex\mathit{Sex}. In the variables list, we move Sex\mathit{Sex} to position V0 and select the corresponding Reference Engine.

Sex-independent reference settings
Click to Zoom

The Residual Plot shows the results:

Loading SVG...
Click to Zoom

We see that on the basis of the χ2\chi^2-Test, we cannot reject the Null-Hypothesis that Sex\mathit{Sex} is independent. However, DD 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 Eye Color\mathit{Eye\ Color} is independent of Sex\mathit{Sex} conditional on Hair Color\mathit{Hair\ Color}. We arrange the variables accordingly in the Variables list.

Conditional-independence reference settings
Click to Zoom

Indeed, the Residual Plot appears to confirm our speculation:

Loading SVG...
Click to Zoom

We see that on the basis of the χ2\chi^2-Test, we cannot reject the Null-Hypothesis that Sex\mathit{Sex} and Eye Color\mathit{Eye\ Color} are independent conditional on Hair Color\mathit{Hair\ Color}. As indicated by the Tooltips, all DD 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.

Fixed-size chart with native scrollbar
Click to Zoom

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...
Click to Zoom
Loading SVG...
Click to Zoom