| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>Covariance & TableOfReal: To TableOfReal (mahalanobis)...</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 |
Covariance & TableOfReal: To TableOfReal (mahalanobis)... |
| 13 |
</b></font></table></table> |
| 14 |
<p>Calculate <a href="Mahalanobis_distance.html">Mahalanobis distance</a> for the selected <a href="TableOfReal.html">TableOfReal</a> with respect to the selected <a href="Covariance.html">Covariance</a> object.</p> |
| 15 |
<h2>Setting</h2> |
| 16 |
<dl> |
| 17 |
<dt><b>Use table centroid</b> |
| 18 |
<dd>Use the mean vector calculated from the columns in the selected TableOfReal instead of the means in the selected Covariance.</dd> |
| 19 |
</dl> |
| 20 |
<h2>Example</h2> |
| 21 |
<p>Count the number of items that are within 1, 2, 3, 4 and 5 standard deviations from the mean.</p> |
| 22 |
<p>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.</p> |
| 23 |
<code> n = 100000<br></code> |
| 24 |
<code> t0 = Create TableOfReal: "table", n, 1<br></code> |
| 25 |
<code> Formula: ~ randomGauss (0, 1)<br></code> |
| 26 |
<code> c = To Covariance<br></code> |
| 27 |
<code> selectObject: c, t0<br></code> |
| 28 |
<code> ts = To TableOfReal (mahalanobis): "no"<br></code> |
| 29 |
<code> <br></code> |
| 30 |
<code> for nsigma to 5<br></code> |
| 31 |
<code> selectObject: ts<br></code> |
| 32 |
<code> extraction = Extract rows where: ~ self < nsigma<br></code> |
| 33 |
<code> nr = Get number of rows<br></code> |
| 34 |
<code> nrp = nr / n * 100<br></code> |
| 35 |
<code> expect = (1 - 2 * gaussQ (nsigma)) * 100<br></code> |
| 36 |
<code> writeInfoLine: nsigma, "-sigma: ", nrp, "%, ", expect, "%"<br></code> |
| 37 |
<code> removeObject: extraction<br></code> |
| 38 |
<code> endfor<br></code> |
| 39 |
<h3>Links to this page</h3> |
| 40 |
<ul> |
| 41 |
<li><a href="Discriminant___TableOfReal__To_TableOfReal__mahalanobis.html">Discriminant & TableOfReal: To TableOfReal (mahalanobis)...</a> |
| 42 |
</ul> |
| 43 |
<hr> |
| 44 |
<address> |
| 45 |
<p>© djmw 20170828</p> |
| 46 |
</address> |
| 47 |
</body> |
| 48 |
</html> |