File: Distance.html

package info (click to toggle)
cluster3 1.59%2Bds-3
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, sid
  • size: 5,624 kB
  • sloc: ansic: 9,948; python: 2,018; perl: 1,566; makefile: 132; sh: 27
file content (475 lines) | stat: -rw-r--r-- 18,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.6, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Distance (Cluster 3.0 for Windows, Mac OS X, Linux, Unix)</title>

<meta name="description" content="Distance (Cluster 3.0 for Windows, Mac OS X, Linux, Unix)">
<meta name="keywords" content="Distance (Cluster 3.0 for Windows, Mac OS X, Linux, Unix)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Contents.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Cluster.html#Cluster" rel="next" title="Cluster">
<link href="Data.html#Data" rel="prev" title="Data">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="Distance"></span><div class="header">
<p>
Next: <a href="Cluster.html#Cluster" accesskey="n" rel="next">Cluster</a>, Previous: <a href="Data.html#Data" accesskey="p" rel="prev">Data</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Contents.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<hr>
<span id="Distance_002fSimilarity-measures"></span><h2 class="chapter">3 Distance/Similarity measures</h2>

<p>The first choice that must be made is how similarity (or alternatively, distance) between gene expression data is to be defined. There are many
ways to compute how similar two series of numbers are. Cluster provides eight
options.
</p>
<span id="Distance-measures-based-on-the-Pearson-correlation"></span><h3 class="section">3.1 Distance measures based on the Pearson correlation</h3>

<p>The most commonly used similarity metrics are based on Pearson
correlation.
The Pearson correlation coefficient between any two series of numbers
<i>x</i> = {<i>x</i><SUB>1</SUB>, <i>x</i><SUB>2</SUB>, ..., <i>x<SUB>n</SUB></i>}
 and
<i>y</i> = {<i>y</i><SUB>1</SUB>, <i>y</i><SUB>2</SUB>, ..., <i>y<SUB>n</SUB></i>}
 is defined as
<DIV ALIGN=center>
<table cellpadding=0 cellspacing=0>
<tr>
<td nowrap><i>r</i> = </td>
<td nowrap>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=CENTER>1</td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>n</i></td></tr>
  </table>
</td>
<td></td>
<td align="center"><i>n</i><br>
  <big><big><big>&#8721;</big></big></big><small><br>
  <i>i</i><small> </small>=<small> </small>1</small></td>
<td><big><big><big><big><big>(</big></big></big></big></big></td>
<td>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=center><i>x<sub>i</sub></i> - <span style="text-decoration: overline;"><i>x</i> </span></td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>&sigma;<sub>x</sub></i></td></tr>
  </table>
</td>
<td><big><big><big><big><big>)</big></big></big></big></big></td>
<td><big><big><big><big><big>(</big></big></big></big></big></td>
<td>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=center><i>y<sub>i</sub></i> - <span style="text-decoration: overline;"><i>y</i> </span></td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>&sigma;<sub>y</sub></i></td></tr>
  </table>
</td>
<td><big><big><big><big><big>)</big></big></big></big></big></td>
</tr>
</table>
</div>
</p>
<p>where
<span style="text-decoration: overline;"><i>x</i></span>
 is the average of values in
<i>x</i>
 and
&sigma;<SUB><i>x</i></SUB>
 is the standard deviation of these values.
</p>
<p>There are many ways of conceptualizing the correlation coefficient. If you were to make
a scatterplot of the values of
<i>x</i>
 against
<i>y</i>
 (pairing
<i>x</i><SUB>1</SUB>
 with
<i>y</i><SUB>1</SUB>, <i>x</i><SUB>2</SUB>
 with
<i>y</i><SUB>2</SUB>,
 etc), then
<i>r</i>
 reports how well you can fit a line to the values.
</p>

<p>The simplest way to think about the correlation coefficient is to plot
<i>x</i>
 and
<i>y</i>
 as curves, with
<i>r</i>
 telling you how similar the shapes of the two curves are.
The Pearson correlation coefficient is always between -1 and 1, with 1 meaning that the two
series are identical, 0 meaning they are completely uncorrelated, and -1 meaning they are
perfect opposites. The correlation coefficient is invariant under linear transformation of
the data. That is, if you multiply all the values in
<i>y</i>
 by 2, or add 7 to all the values in
<i>y</i>,
 the correlation between
<i>x</i>
 and
<i>y</i>
 will be unchanged. Thus, two curves that have identical shape, but different
magnitude, will still have a correlation of 1.
</p>
<p>Cluster actually uses four different flavors of the Pearson correlation. The textbook
Pearson correlation coefficient, given by the formula above, is used if you select
Correlation (centered) in the Similarity Metric dialog box.
Correlation (uncentered) uses the following modified equations:<br>
<DIV ALIGN=center>
<table cellpadding=0 cellspacing=0>
<tr>
<td nowrap><i>r</i> = </td>
<td nowrap>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=CENTER>1</td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>n</i></td></tr>
  </table>
</td>
<td></td>
<td align="center"><i>n</i><br>
  <big><big><big>&#8721;</big></big></big><small><br>
  <i>i</i><small> </small>=<small> </small>1</small></td>
<td><big><big><big><big><big>(</big></big></big></big></big></td>
<td>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=center><i>x<sub>i</sub></i></td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>&sigma;<sub>x</sub></i><sup>(0)</sup></td></tr>
  </table>
</td>
<td><big><big><big><big><big>)</big></big></big></big></big></td>
<td><big><big><big><big><big>(</big></big></big></big></big></td>
<td>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=center><i>y<sub>i</sub></i></td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>&sigma;<sub>y</sub></i><sup>(0)</sup></td></tr>
  </table>
</td>
<td><big><big><big><big><big>)</big></big></big></big></big></td>
</tr>
</table>
</div>
<br>
in which<br>
<DIV ALIGN=center>
<table cellpadding=0 cellspacing=0>
<tr>
<td nowrap><i>&sigma;<sub>x</sub></i><sup>(0)</sup> = </td>
<td><big><big><big>&#8730; </big></big></big></td>
<td><big><big><big><big><big>(</big></big></big></big></big></td>
<td nowrap>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=CENTER>1</td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>n</i></td></tr>
  </table>
</td>
<td></td>
<td align="center"><i>n</i><br>
  <big><big><big>&#8721;</big></big></big><small><br>
  <i>i</i><small> </small>=<small> </small>1</small></td>
<td><i>x<sub>i</sub></i><sup>2</sup></td>
<td><big><big><big><big><big>)</big></big></big></big></big></td>
</tr>
</table>
</div>
<DIV ALIGN=center>
<table cellpadding=0 cellspacing=0>
<tr>
<td nowrap><i>&sigma;<sub>y</sub></i><sup>(0)</sup> = </td>
<td><big><big><big>&#8730; </big></big></big></td>
<td><big><big><big><big><big>(</big></big></big></big></big></td>
<td nowrap>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=CENTER>1</td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>n</i></td></tr>
  </table>
</td>
<td></td>
<td align="center"><i>n</i><br>
  <big><big><big>&#8721;</big></big></big><small><br>
  <i>i</i><small> </small>=<small> </small>1</small></td>
<td><i>y<sub>i</sub></i><sup>2</sup></td>
<td><big><big><big><big><big>)</big></big></big></big></big></td>
</tr>
</table>
</div>
<br>
This is basically the same function, except that it assumes the mean is 0, even when it is not. The difference is that, if you have two vectors
<i>x</i>
 and
<i>y</i>
 with identical shape, but which are offset relative to each other by a fixed value, they will have a standard Pearson correlation (centered correlation) of 1 but will not have an uncentered correlation of 1.
The uncentered correlation is equal to the cosine of the angle of two
<i>n</i>-dimensional
 vectors
<i>x</i>
 and
<i>y</i>,
 each representing a vector in
<i>n</i>-dimensional
 space that passes through the origin.
Cluster provides two similarity metrics that are the absolute value of these two correlation functions, which consider two items to be similar if they have opposite expression patterns; the standard correlation coefficients consider opposite genes to be very distant.
</p>
<span id="Non_002dparametric-distance-measures"></span><h3 class="section">3.2 Non-parametric distance measures</h3>

<p>The Spearman rank correlation and Kendall&rsquo;s
<i>&tau;</i>
 are two additional metrics, which are non-parametric versions of the Pearson correlation coefficient. These methods are more robust against outliers.
</p>
<p>The Spearman rank correlation calculates the correlation between the ranks of the data values in the two vectors. For example, if we have two data vectors<br>
<DIV align=center>
<i>x</i> = {2.3, 6.7, 4.5, 20.8};<br>
<i>y</i> = {2.1, 5.9, 4.4, 4.2},<br>
</DIV>
then we first replace them by their ranks:<br>
<DIV align=center>
<i>x</i> = {1, 3, 2, 4};<br>
<i>y</i> = {1, 4, 3, 2}.<br>
</DIV>
Now we calculate the correlation coefficient in their usual manner from these data vectors, resulting in<br>
<DIV align=center>
<i>r</i><sub>Spearman</sub> = 0.4.
</DIV>
In comparison, the regular Pearson correlation between these data is
<i>r</i> = 0.2344.
By replacing the data values by their ranks, we reduced the effect of the outlier 20.8 on the value of the correlation coefficient. The Spearman rank correlation can be used as a test statistic for independence between
<i>x</i> and <i>y</i>.
For more information, see Conover (1980).
</p>
<p>Kendall&rsquo;s
<i>&tau;</i>
 goes a step further by using only the relative ordering of
<i>x</i> and <i>y</i>
 to calculate the correlation (Snedecor &amp; Cochran). To calculate Kendall&rsquo;s
<i>&tau;</i>,
 consider all pairs of data points
(<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) and (<i>x<sub>j</sub></i>, <i>y<sub>j</sub></i>).
We call a pair concordant if
</p><ul>
<li> <i>x<sub>i</sub></i> &lt; <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> &lt; <i>y<sub>j</sub></i>; or
</li><li> <i>x<sub>i</sub></i> &gt; <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> &gt; <i>y<sub>j</sub></i>,
</li></ul>
<p>and discordant if
</p><ul>
<li> <i>x<sub>i</sub></i> &lt; <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> &gt; <i>y<sub>j</sub></i>; or
</li><li> <i>x<sub>i</sub></i> &gt; <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> &lt; <i>y<sub>j</sub></i>.
</li></ul>
<p>We can represent this by a table:
<DIV ALIGN=center>
<table cellpadding=10 cellspacing=0 border=1>
<tr align=center>
  <td>-</td>
  <td>(2.3, 2.1)</td>
  <td>(6.7, 5.9)</td>
  <td>(4.5, 4.4)</td>
  <td>(20.8, 4.2)</td>
</tr>
<tr align=center>
  <td>(2.3, 2.1)</td>
  <td>-</td>
  <td>&lt;&lt;</td>
  <td>&lt;&lt;</td>
  <td>&lt;&lt;</td>
</tr>
<tr align=center>
  <td>(6.7, 5.9)</td>
  <td>&gt;&gt;</td>
  <td>-</td>
  <td>&gt;&gt;</td>
  <td>&lt;&gt;</td>
</tr>
<tr align=center>
  <td>(4.5, 4.4)</td>
  <td>&gt;&gt;</td>
  <td>&lt;&lt;</td>
  <td>-</td>
  <td>&lt;&gt;</td>
</tr>
<tr align=center>
  <td>(20.8, 4.2)</td>
  <td>&gt;&gt;</td>
  <td>&gt;&lt</td>
  <td>&gt;&lt</td>
  <td>-</td>
</tr>
</table>
</DIV>
From this table, we find that there are four concordant pairs and two discordant pairs:
<DIV align=center>
<i>n</i><sub>c</sub> = 4;<br>
<i>n</i><sub>d</sub> = 2.<br>
</DIV>
Kendall&rsquo;s
<i>&tau;</i>
 is calculated as<br>
<DIV ALIGN=center>
<table cellspacing=0 cellpadding=0>
<tr>
  <td><i>&tau;</i> = </td>
  <td> </td>
  <td>
    <table cellspacing=0 cellpadding=0>
      <tr>
        <td nowrap align=CENTER>
          <i>n</i><sub>c</sub>-<i>n</i><sub>d</sub>
        </td>
      </tr>
      <tr>
        <td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td>
      </tr>
      <tr>
        <td nowrap align=CENTER>
          <i>n</i>(<i>n</i>-1)/2
        </td>
      </tr>
    </table>
  </td>
  <td>,</td>
</tr>
</table>
</DIV>
 which in this case evaluates as 0.33. In the C Clustering Library, the calculation of Kendall&rsquo;s
<i>&tau;</i>
 is corrected for the possibility that two ranks are equal.
As in case of the Spearman rank correlation, we may use Kendall&rsquo;s
<i>&tau;</i>
 to test for independence between
<i>x</i> and <i>y</i>.
</p>
<span id="Distance-measures-related-to-the-Euclidean-distance"></span><h3 class="section">3.3 Distance measures related to the Euclidean distance</h3>

<span id="Euclidean-distance"></span><h4 class="subsection">3.3.1 Euclidean distance</h4>

<p>A newly added distance function is the Euclidean distance, which is defined as
<DIV ALIGN=center>
<table cellpadding=0 cellspacing=0>
<tr>
<td nowrap><i>d</i> = </td>
<td nowrap>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=CENTER>1</td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>n</i></td></tr>
  </table>
</td>
<td></td>
<td align="center"><i>n</i><br>
  <big><big><big>&#8721;</big></big></big><small><br>
  <i>i</i><small> </small>=<small> </small>1</small>
</td>
<td><big>(</big></td>
<td><i>x<sub>i</sub></i> - <i>y<sub>i</sub></i></td>
<td><big>)</big><sup>2</sup></td>
</tr>
</table>
</div>
The Euclidean distance takes the difference between two gene expression levels directly. It should therefore only be used for expression data that are suitably normalized, for example by converting the measured gene expression levels to log-ratios. In the sum, we only include terms for which both
<i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>
 are present, and divide by
<i>n</i>
 accordingly.
</p>
<p>Unlike the correlation-based distance measures, the Euclidean distance takes the magnitude of changes in the gene expression levels into account. An example of the Euclidean distance applied to 
<i>k</i>-means
 clustering can be found in De Hoon, Imoto, and Miyano (2002).
</p>
<span id="City_002dblock-distance"></span><h4 class="subsection">3.3.2 City-block distance</h4>

<p>The city-block distance, alternatively known as the Manhattan distance, is related to the Euclidean distance. Whereas the Euclidean distance corresponds to the length of the shortest path between two points, the city-block distance is the sum of distances along each dimension:
<DIV ALIGN=center>
<table cellpadding=0 cellspacing=0>
<tr>
<td nowrap><i>d</i> = </td>
<td nowrap>
  <table cellspacing=0 cellpadding=0>
  <tr><td nowrap align=CENTER>1</td></tr>
  <tr><td bgcolor=BLACK><table border=0 width="100%" cellspacing=0 cellpadding=1><tr><td></td></tr></table></td></tr>
  <tr><td nowrap align=CENTER><i>n</i></td></tr>
  </table>
</td>
<td></td>
<td align="center"><i>n</i><br>
  <big><big><big>&#8721;</big></big></big><small><br>
  <i>i</i><small> </small>=<small> </small>1</small></td>
<td><big>|</big></td>
<td><i>x<sub>i</sub></i> - <i>y<sub>i</sub></i></td>
<td><big>|</big></td>
</tr>
</table></div>
This is equal to the distance you would have to walk between two points in a city, where you have to walk along city blocks. The city-block distance is a metric, as it satisfies the triangle inequality. Again we only include terms for which both
<i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>
 are present, and divide by
<i>n</i>
 accordingly.
</p>
<p>As for the Euclidean distance, the expression data are subtracted directly from each other, and we should therefore make sure that they are properly normalized.
</p>

<span id="Missing-values"></span><h3 class="section">3.4 Missing values</h3>

<p>When either
<i>x</i>
 or
<i>y</i>
 has missing values, only observations present for both
<i>x</i>
 and
<i>y</i>
 are used in computing similarities.
</p>
<span id="Calculating-the-distance-matrix"></span><h3 class="section">3.5 Calculating the distance matrix</h3>

<p>With any specified metric, the first step in the hierarchical clustering routines described below is to compute the
distance (the opposite of similarity; for all correlation metrics distance = 1.0 - correlation)
between all pairs of items to be clustered (e.g. the set of genes in the current dataset).
This can often be time consuming, and, except for pairwise single-linkage clustering,
memory intensive (the maximum amount of memory required is
4 x <i>N</i> x <i>N</i>
 bytes, where
<i>N</i>
 is the number of items being clustered). The algorithm for pairwise single-linkage hierarchical clustering is less memory-intensive (linear in
<i>N</i>).
</p>
<hr>
<div class="header">
<p>
Next: <a href="Cluster.html#Cluster" accesskey="n" rel="next">Cluster</a>, Previous: <a href="Data.html#Data" accesskey="p" rel="prev">Data</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Contents.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>



</body>
</html>