Covariance & TableOfReal: To TableOfReal (mahalanobis)...

Calculate Mahalanobis distance for the selected TableOfReal with respect to the selected Covariance object.

Setting

Use table centroid
Use the mean vector calculated from the columns in the selected TableOfReal instead of the means in the selected Covariance.

Example

Count the number of items that are within 1, 2, 3, 4 and 5 standard deviations from the mean.

We first create a table with only one column and 10000 rows and fill it with numbers drawn from a normal distribution with mean zero and standard deviation one. Its covariance matrix, of course, is one dimensional. We next create a table with Mahalanobis distances.

n = 100000
t0 = Create TableOfReal: "table", n, 1
Formula: ~ randomGauss (0, 1)
c = To Covariance
selectObject: c, t0
ts = To TableOfReal (mahalanobis): "no"

for nsigma to 5
selectObject: ts
extraction = Extract rows where: ~ self < nsigma
nr = Get number of rows
nrp = nr / n * 100
expect = (1 - 2 * gaussQ (nsigma)) * 100
writeInfoLine: nsigma, "-sigma: ", nrp, "%, ", expect, "%"
removeObject: extraction
endfor

Links to this page


© djmw 20170828