mahalCorAna

mahalCorAna computes Mahalanobis distances (in squared units) for each row of matrix Y

Syntax

Description

example

d =mahalCorAna(Y, MU) Example of computation of MD.

Examples

expand all

  • Example of computation of MD.
  • Generate a contingency table.

    nrow=30;
    ncol=5;
    % Fix the marginals of the two rows
    nrowt=200*ones(1,nrow);
    % Fix the marginals of the three columns
    ncolt=1200*ones(ncol,1);
    % Generate the contingency table
    out=rcontFS(nrow,ncol,nrowt,ncolt);
    N=out.m144;
    MU=sum(N,1)/sum(nrowt); 
    % Compute MD ;
    n=sum(N,'all');
    P=N/n;
    ProfileRows=P./sum(P,1);
    d=mahalCorAna(ProfileRows,MU);

    Related Examples

    expand all

  • Find total inertial of contingency table Generate a contingency table.
  • nrow=30;
    ncol=5;
    % Fix the marginals of the two rows
    nrowt=200*ones(1,nrow);
    % Fix the marginals of the three columns
    ncolt=1200*ones(ncol,1);
    % Generate the contingency table
    out=rcontFS(nrow,ncol,nrowt,ncolt);
    N=out.m144;
    n=sum(N,'all');
    P=N/n;
    r=sum(P,2); % row masses
    c=sum(P,1); % centroid of row masses
    ProfileRows=P./r;
    d2=r.*mahalCorAna(ProfileRows,c);
    % d2 is the total inertia
    disp('Total inertia')
    disp(sum(d2));

    Input Arguments

    expand all

    Y — Input data. Matrix.

    I x J Profile rows matrix; n observations and v variables.

    Rows of Y represent observations, and columns represent variables.

    Data Types: single|double

    MU — Centroid. Vector.

    1 x J vector containing centroid and covariance matrix to use

    Data Types: single| double

    Output Arguments

    expand all

    d —Mahalanobis distances. Vector

    n x 1 vector which contains the squared Mahalanobid distances.

    \[ d(i) = (y_i-\mu)^T \times diag(\mu)^{-1} \times (y_i-\mu), \qquad i=1, 2, \ldots, n \]

    References

    See Also

    This page has been automatically generated by our routine publishFS