crosstab2datamatrix

crosstab2datamatrix recreates the original data matrix X from contingency table N

Syntax

  • X=crosstab2datamatrix(N)example
  • X=crosstab2datamatrix(N,Name,Value)example
  • [X,T]=crosstab2datamatrix(___)example

Description

example

X =crosstab2datamatrix(N) crosstab2datamatrix with all the default options.

example

X =crosstab2datamatrix(N, Name, Value) crosstab2datamatrix when input is a contingency table of class table.

example

[X, T] =crosstab2datamatrix(___) Example of use of option Lc.

Examples

expand all

  • crosstab2datamatrix with all the default options.
  • In this case the input is a contingency table of class double.

    N=[26 26 23 18 9;
    6  7  9 14 23];
    % No labels for rows and columns are supplied
    X=crosstab2datamatrix(N);

  • crosstab2datamatrix when input is a contingency table of class table.
  • N = [24 23 30; 
    19 43 57;
    13 33 58];
    rownam={'Less_than_5000',  'Between_5000_and_25000' 'Greater_than_25000'};
    colnam= {'Dissatisfied' 'Moderately_satisfied' 'Very_satisfied'};
    if verLessThan('matlab','8.2.0') ==0
    Ntable=array2table(N,'RowNames',matlab.lang.makeValidName(rownam),'VariableNames',matlab.lang.makeValidName(colnam));
    %  Check relationship
    X=crosstab2datamatrix(Ntable);
    else
    X=crosstab2datamatrix(N,'Lr',rownam,'Lc',colnam);
    end
    disp('Compare original contingency table and the one passing through X')
    disp('Original contingency table')
    disp(N)
    disp('Contingency table obtained using crosstab applied to reconstructed original data matrix')
    disp(crosstab(X(:,1),X(:,2)))
    Compare original contingency table and the one passing through X
    Original contingency table
        24    23    30
        19    43    57
        13    33    58
    
    Contingency table obtained using crosstab applied to reconstructed original data matrix
        24    23    30
        19    43    57
        13    33    58
    
    

  • Example of use of option Lc.
  • In this case just the column names are supplied The default row labels 'r1' 'r2' 'r3' are used

    N = [24 23 30; 
    19 43 57;
    13 33 58];
    colnam= {'Dissatisfied' 'Moderately_satisfied' 'Very_satisfied'};
    X=crosstab2datamatrix(N,'Lc',colnam);

    Input Arguments

    expand all

    N — Contingency table (default). Matrix or Table which contains the input contingency table of size I-by-J.

    It contains the frequencies which have to be inflated. The output data matrix will have size sum(N(:))-by-2.

    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: 'Lr',{'a' 'b' 'c'} , 'Lc',{'c1' c2' 'c3' 'c4'}

    Lr —Vector of row labels.cell of length I.

    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 of lenght J.

    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

    X —Original data matrix. cell or numeric matrix

    Object of class double or cell of size sum(N(:))-by-2 containing the original data matrix.

    Original input which generated the contingency table.

    Note that input N can be obtained using N=crosstab(X(:,1),X(:,2));

    T —Original data matrix in table format. Object of class table of size sum(N(:))-by-2 containing the original data matrix

    Original input which generated the contingency table.

    Note that input N can be obtained using N=crosstab(T{:,1},X{:,2});

    If the labels contained in Lr and Lr could be converted to double the columns of T contain numeric values else their class is categorical

    References

    This page has been automatically generated by our routine publishFS