balloonplot

balloonplot creates a balloon plot of a contingency table

Syntax

Description

A balloonplot is an alternative to bar plot for visualizing a large categorical data. It draws a graphical matrix of a contingency table, where each cell contains a dot whose size reflects the relative magnitude of the corresponding component. ballonplot is a bubble chart for contingency tables.

example

h =balloonplot(N) balloonplot with table input.

example

h =balloonplot(N, Name, Value) balloonplot with array input.

example

[h, Ntable] =balloonplot(___) balloonplot with original data matrix as input.

Examples

expand all

  • balloonplot with table input.
  • Load the Housetasks data (a contingency table containing the frequency of execution of 13 house tasks in the couple).

    N=[156	14	2	4;
    124	20	5	4;
    77	11	7	13;
    82	36	15	7;
    53	11	1	57;
    32	24	4	53;
    33	23	9	55;
    12	46	23	15;
    10	51	75	3;
    13	13	21	66;
    8	1	53	77;
    0	3	160	2;
    0	1	6	153];
    rowslab={'Laundry' 'Main-meal' 'Dinner' 'Breakfast' 'Tidying' 'Dishes' ...
    'Shopping' 'Official' 'Driving' 'Finances' 'Insurance'...
    'Repairs' 'Holidays'};
    colslab={'Wife'	'Alternating'	'Husband'	'Jointly'};
    tableN=array2table(N,'VariableNames',colslab,'RowNames',rowslab);
    % In this case a table is supplied
    balloonplot(tableN);
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • balloonplot with array input.
  • Load the Housetasks data (a contingency table containing the frequency of execution of 13 house tasks in the couple).

    N=[156	14	2	4;
    124	20	5	4;
    77	11	7	13;
    82	36	15	7;
    53	11	1	57;
    32	24	4	53;
    33	23	9	55;
    12	46	23	15;
    10	51	75	3;
    13	13	21	66;
    8	1	53	77;
    0	3	160	2;
    0	1	6	153];
    rowslab={'Laundry' 'Main-meal' 'Dinner' 'Breakfast' 'Tidying' 'Dishes' ...
    'Shopping' 'Official' 'Driving' 'Finances' 'Insurance'...
    'Repairs' 'Holidays'};
    colslab={'Wife'	'Alternating'	'Husband'	'Jointly'};
    tableN=array2table(N,'VariableNames',colslab,'RowNames',rowslab);
    % In this case row and columns labels are supplied through options Lr
    % and Lc
    balloonplot(N,'Lr',rowslab,'Lc',colslab);

  • balloonplot with original data matrix as input.
  • load smoke
    [h,Ntable]=balloonplot(smoke,'datamatrix',true);
    disp(Ntable)
                            None    Light    Medium    Heavy
                            ____    _____    ______    _____
    
        Senior_Managers       4       2         3        2  
        Junior_Managers       4       3         7        4  
        Senior_Employees     25      10        12        4  
        Junior_Employees     18      24        33       13  
        Secretaries          10       6         7        2  
    
    
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Related Examples

    expand all

  • balloonplot with option contrib2Index as boolean.
  • Load the Housetasks data (a contingency table containing the frequency of execution of 13 house tasks in the couple).

    % This ia a German sample in young, married, heterosexual couples in the late 1970s,
    N=[156	14	2	4;
    124	20	5	4;
    77	11	7	13;
    82	36	15	7;
    53	11	1	57;
    32	24	4	53;
    33	23	9	55;
    12	46	23	15;
    10	51	75	3;
    13	13	21	66;
    8	1	53	77;
    0	3	160	2;
    0	1	6	153];
    rowslab={'Laundry' 'Main-meal' 'Dinner' 'Breakfast' 'Tidying' 'Dishes' ...
    'Shopping' 'Official' 'Driving' 'Finances' 'Insurance'...
    'Repairs' 'Holidays'};
    colslab={'Wife'	'Alternating'	'Husband'	'Jointly'};
    % If the DimensionNames is set the xlabel and ylabel will be added
    % automatically.
    Ntable=array2table(N,'VariableNames',colslab,'RowNames',rowslab);
    Ntable.Properties.DimensionNames=["Repartition in the couple" "13 housetasks"];
    % Call to balloonplot with option 'contrib2Index' boolean equal to
    % true. In this case the contributions to the Chi2 statistic
    % are shown. The color is associated to the sign.
    balloonplot(Ntable,'contrib2Index',true);
    Click here for the graphical output of this example (link to Ro.S.A. website)

  • Example of ballonplot with option contrib2Index as a matrix.
  • load SportHealth.mat
    out=corrOrdinal(SportHealth);
    balloonplot(SportHealth,'contrib2Index',out.Contrib2CminusD)
    Test of H_0: independence between rows and columns
    The standard errors are computed under H_0
                  Coeff        se       zscore    pval
                 _______    ________    ______    ____
    
        gamma    0.59385    0.053088    11.186     0  
        taua     0.33958     0.03852    8.8157     0  
        taub     0.45635    0.040796    11.186     0  
        tauc     0.45128    0.040343    11.186     0  
        dyx       0.4525    0.040451    11.186     0  
    
    -----------------------------------------
    Indexes and 95% confidence limits
    The standard error are computed under H_1
                  Value     StandardError    ConflimL    ConflimU
                 _______    _____________    ________    ________
    
        gamma    0.59385       0.04837       0.49905     0.68866 
        taua     0.33958      0.011291       0.31745     0.36171 
        taub     0.45635      0.040331        0.3773      0.5354 
        tauc     0.45128      0.040343       0.37221     0.53036 
        dyx       0.4525      0.040106       0.37389     0.53111 
    
    
    ans = 
    
      Figure (Figure) with properties:
    
          Number: []
            Name: 'Figure'
           Color: [0.9400 0.9400 0.9400]
        Position: [488 241.8000 560 420.0000]
           Units: 'pixels'
    
      Use GET to show all properties
    
    
    Click here for the graphical output of this example (link to Ro.S.A. website)

  • Example where contrib2Index is a table.
  • load SportHealth.mat
    out=corrNominal(SportHealth);
    out.Contrib2Hyxtable
    % Contribution to Hyx index from each cell of the table
    balloonplot(SportHealth,'contrib2Index', out.Contrib2Hyxtable)
    title(['Contribution of each single cell to Hyx=' num2str(out.Hyx(1))])
    Chi2 index
      104.4294
    
    pvalue Chi2 index
       1.9934e-18
    
    Phi index
        0.5871
    
    Cramer's V 
        0.3389
    
    Test of H_0: independence between rows and columns
                       Coeff        se       zscore       pval   
                      _______    ________    ______    __________
    
        CramerV       0.33895    0.040732    8.3214             0
        GKlambdayx    0.19307    0.044247    4.3634    1.2803e-05
        tauyx         0.11153    0.021133    5.2774    1.3104e-07
        Hyx           0.12654    0.022713    5.5711     2.531e-08
    
    -----------------------------------------
    Indexes and 95% confidence limits
                       Value     StandardError    ConflimL    ConflimU
                      _______    _____________    ________    ________
    
        CramerV       0.33895      0.040732        0.25911    0.39187 
        GKlambdayx    0.19307      0.044247        0.10635    0.27979 
        tauyx         0.11153      0.021133       0.070107    0.15295 
        Hyx           0.12654      0.022713       0.082019    0.17105 
    
    
    ans =
    
      4×4 table
    
                     Poor Health    Fair Health    Good Health    Excellent Health
                     ___________    ___________    ___________    ________________
    
        Never          0.065383       0.030991      -0.020606        -0.016491    
        Rarely        0.0011911        0.01432      0.0059075        -0.015609    
        Sometimes     -0.012717      -0.013736        0.04043        0.0057804    
        Often        -0.0086721        -0.0125     -0.0060879         0.068952    
    
    
    ans = 
    
      Figure (Figure) with properties:
    
          Number: []
            Name: 'Figure'
           Color: [0.9400 0.9400 0.9400]
        Position: [488 241.8000 560 420.0000]
           Units: 'pixels'
    
      Use GET to show all properties
    
    
    Click here for the graphical output of this example (link to Ro.S.A. website)

    Input Arguments

    expand all

    N — Contingency table (default) or n-by-2 input dataset. 2D Array or Table.

    2D array or table which contains the input contingency table (say of size I-by-J) or the original data matrix X.

    In this last case N=crosstab(X(:,1),X(:,2)). As default procedure assumes that the input is a contingency table.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'ax',myaxes , 'contrib2Chi2',true , 'datamatrix',true , 'Lr',{'a' 'b' 'c'} , 'Lc',{'c1' c2' 'c3' 'c4'}

    ax —displays the bubble chart in the target axes ax.axes object.

    If you do not specify the axes, MATLAB plots into the current axes, or it creates an Axes object if one does not exist.

    Example: 'ax',myaxes

    Data Types: Axes object

    contrib2Index —bubble chart of contribution to a statistic index.boolean | matrix (table) of size IxJ.

    If this option is true, squared Pearson rediduals are computed and shown through bubble chart. Squared Pearson residuals associated with positive (negative) associations are shown in blue (red). Pearson residuals are defined as ${n_{ij}-n_{ij}^*})/{\sqrt{n_{ij}^*}$ where $n_{ij}$ is the $i,j$ entry of the input contingency table N and $n_{ij}^*$ is the theoretical frequency under the independence hypothesis. The sum of the squares of the Pearson residuals is equal to the $Chi^2$ statistic to test the independence between rows and columns of the contingency table. The default value of contrib2INdex is false that is no transformation is done on the orginal contingency table. If contrib2INdex is equal to a matrix of size IxJ the balloon plots shows circles which are proportional to the absolute values of this matrix.

    Example: 'contrib2Chi2',true

    Data Types: boolean or array or table of the same size of N

    datamatrix —Data matrix or contingency table.boolean.

    If datamatrix is true the first input argument N is forced to be interpreted as a data matrix, else if the input argument is false N is treated as a contingency table. The default value of datamatrix is false, that is the procedure automatically considers N as a contingency table (in array or table format). If datamatrix is true, N can be an array or a table of size n-by-2. Note that if N has more than two columns balloonplot is based on the first two columns of N (and a warning is produced).

    Example: 'datamatrix',true

    Data Types: logical

    Lr —Vector of row labels.cell.

    Cell containing the labels of the rows of the input contingency matrix N. This option is unnecessary if N is a table, because in this case Lr=N.Properties.RowNames;

    Example: 'Lr',{'a' 'b' 'c'}

    Data Types: cell array of strings

    Lc —Vector of column labels.cell.

    Cell containing the labels of the columns of the input contingency matrix N. This option is unnecessary if N is a table, because in this case Lc=N.Properties.VariableNames;

    Example: 'Lc',{'c1' c2' 'c3' 'c4'}

    Data Types: cell array of strings

    Output Arguments

    expand all

    h —returns the BubbleChart object. Use h to modify properties of the chart after creating it

    For a list of properties, see BubbleChart Properties.

    Ntable —$I$-by-$J$ contingency table. Table

    This is tha table which has been used to build the balloonplot.

    References

    This page has been automatically generated by our routine publishFS