mdPartialMD

mdPartialMD computes squared Mahalanobis distances using only observed entries.

Syntax

  • d2=mdPartialMD(Y, mu, Sigma)example
  • [d2, pobs]=mdPartialMD(___)example

Description

The function computes for each row i the (squared) Mahalanobis distance:

d2(i) = (x_obs - mu_obs)' * inv(Sigma_obs_obs) * (x_obs - mu_obs) where obs are the indices of non-missing entries in row i.

example

d2 =mdPartialMD(Y, mu, Sigma) Example with just one output argument.

example

[d2, pobs] =mdPartialMD(___) Example with two output arguments.

Examples

expand all

  • Example with just one output argument.
  • number of variables

    p = 5;                
    % number of observations
    n = 100;             
    % target pairwise correlation (0<rho<1)
    rho = 0.9;            
    Sigma = (1-rho)*eye(p) + rho*ones(p);
    % upper-triangular such that Sigma = R'*R
    R = chol(Sigma);      
    % MCAR missing probability per entry
    missRate = 0.01;     
    % Generate samples ~ N(0,Sigma)
    Yfull = randn(n,p) * R;   % Strong positive correlation between the vars
    missMask = rand(n,p) < missRate;
    mu=mean(Yfull)';
    S=cov(Yfull);
    Y=Yfull;
    Y(missMask) = NaN;
    d2fast=mdPartialMD(Y,mu,Sigma);

  • Example with two output arguments.
  • number of variables

    p = 5;                
    % number of observations
    n = 100;             
    % target pairwise correlation (0<rho<1)
    rho = 0.9;            
    Sigma = (1-rho)*eye(p) + rho*ones(p);
    % upper-triangular such that Sigma = R'*R
    R = chol(Sigma);      
    % MCAR missing probability per entry
    missRate = 0.01;     
    % Generate samples ~ N(0,Sigma)
    % Strong positive correlation between the vars
    Yfull = randn(n,p) * R;  
    missMask = rand(n,p) < missRate;
    mu=mean(Yfull)';
    S=cov(Yfull);
    Y=Yfull;
    Y(missMask) = NaN;
    [d2fast,pobs]=mdPartialMD(Y,mu,Sigma);

    Input Arguments

    expand all

    Y — data matrix. 2D array.

    n x p data matrix (rows may contain NaN for missing)

    Data Types: single| double

    mu — location estimate. Vector.

    Vector of length p containing estimate of location

    Data Types: single| double

    Sigma — scatter estimate. Matrix.

    p x p estimated covariance matrix.

    Data Types: single| double

    Output Arguments

    expand all

    d2 —squared Mahalanobis distances (computed on observed dims). n -by- 1 vector

    If a row has zero observed entries, d2(i) is set to NaN.

    pobs —number of observed variables for each row. Vector

    n x 1 vector with number of observed variable for each row of input data matrix X. If a row has zero observed entries poss(i)=0.

    References

    Little, R. J. A., & Rubin, D. B. (2019). Statistical Analysis with Missing Data (3rd ed.). Hoboken, NJ: John Wiley & Sons.

    Templ, M. (2023). Visualization and Imputation of Missing Values: With Applications in R. Cham, Switzerland: Springer Nature.

    This page has been automatically generated by our routine publishFS