File: Descriptive-Statistics.html

package info (click to toggle)
octave 7.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 130,464 kB
  • sloc: cpp: 332,823; ansic: 71,320; fortran: 20,963; objc: 8,562; sh: 8,115; yacc: 4,882; lex: 4,438; perl: 1,554; java: 1,366; awk: 1,257; makefile: 652; xml: 173
file content (736 lines) | stat: -rw-r--r-- 38,662 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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Descriptive Statistics (GNU Octave (version 7.3.0))</title>

<meta name="description" content="Descriptive Statistics (GNU Octave (version 7.3.0))">
<meta name="keywords" content="Descriptive Statistics (GNU Octave (version 7.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Statistics.html" rel="up" title="Statistics">
<link href="Statistics-on-Sliding-Windows-of-Data.html" rel="next" title="Statistics on Sliding Windows of Data">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {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}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<div class="section" id="Descriptive-Statistics">
<div class="header">
<p>
Next: <a href="Statistics-on-Sliding-Windows-of-Data.html" accesskey="n" rel="next">Statistics on Sliding Windows of Data</a>, Up: <a href="Statistics.html" accesskey="u" rel="up">Statistics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Descriptive-Statistics-1"></span><h3 class="section">26.1 Descriptive Statistics</h3>

<p>One principal goal of descriptive statistics is to represent the essence of a
large data set concisely.  Octave provides the mean, median, and mode functions
which all summarize a data set with just a single number corresponding to
the central tendency of the data.
</p>
<span id="XREFmean"></span><dl class="def">
<dt id="index-mean"><span class="category">: </span><span><em></em> <strong>mean</strong> <em>(<var>x</var>)</em><a href='#index-mean' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mean-1"><span class="category">: </span><span><em></em> <strong>mean</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-mean-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mean-2"><span class="category">: </span><span><em></em> <strong>mean</strong> <em>(<var>x</var>, <var>opt</var>)</em><a href='#index-mean-2' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mean-3"><span class="category">: </span><span><em></em> <strong>mean</strong> <em>(<var>x</var>, <var>dim</var>, <var>opt</var>)</em><a href='#index-mean-3' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mean-4"><span class="category">: </span><span><em></em> <strong>mean</strong> <em>(&hellip;, <var>outtype</var>)</em><a href='#index-mean-4' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the mean of the elements of the vector <var>x</var>.
</p>
<p>The mean is defined as
</p>

<div class="example">
<pre class="example">mean (<var>x</var>) = SUM_i <var>x</var>(i) / N
</pre></div>

<p>where <em class='math'>N</em> is the length of the <var>x</var> vector.
</p>
<p>If <var>x</var> is a matrix, compute the mean for each column and return them
in a row vector.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>The optional argument <var>opt</var> selects the type of mean to compute.
The following options are recognized:
</p>
<dl compact="compact">
<dt><span><code>&quot;a&quot;</code></span></dt>
<dd><p>Compute the (ordinary) arithmetic mean.  [default]
</p>
</dd>
<dt><span><code>&quot;g&quot;</code></span></dt>
<dd><p>Compute the geometric mean.
</p>
</dd>
<dt><span><code>&quot;h&quot;</code></span></dt>
<dd><p>Compute the harmonic mean.
</p></dd>
</dl>

<p>The optional argument <var>outtype</var> selects the data type of the
output value.  The following options are recognized:
</p>
<dl compact="compact">
<dt><span><code>&quot;default&quot;</code></span></dt>
<dd><p>Output will be of class double unless <var>x</var> is of class single,
in which case the output will also be single.
</p>
</dd>
<dt><span><code>&quot;double&quot;</code></span></dt>
<dd><p>Output will be of class double.
</p>
</dd>
<dt><span><code>&quot;native&quot;</code></span></dt>
<dd><p>Output will be the same class as <var>x</var> unless <var>x</var> is of class
logical in which case it returns of class double.
</p>
</dd>
</dl>

<p>Both <var>dim</var> and <var>opt</var> are optional.  If both are supplied, either
may appear first.
</p>
<p><strong>See also:</strong> <a href="#XREFmedian">median</a>, <a href="#XREFmode">mode</a>.
</p></dd></dl>


<span id="XREFmedian"></span><dl class="def">
<dt id="index-median"><span class="category">: </span><span><em></em> <strong>median</strong> <em>(<var>x</var>)</em><a href='#index-median' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-median-1"><span class="category">: </span><span><em></em> <strong>median</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-median-1' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the median value of the elements of the vector <var>x</var>.
</p>
<p>When the elements of <var>x</var> are sorted, say
<code><var>s</var> = sort (<var>x</var>)</code>, the median is defined as
</p>
<div class="example">
<pre class="example">             |  <var>s</var>(ceil(N/2))           N odd
median (<var>x</var>) = |
             | (<var>s</var>(N/2) + <var>s</var>(N/2+1))/2   N even
</pre></div>

<p>If <var>x</var> is of a discrete type such as integer or logical, then
the case of even <em class='math'>N</em> rounds up (or toward <code>true</code>).
</p>
<p>If <var>x</var> is a matrix, compute the median value for each column and
return them in a row vector.
</p>
<p>If the optional <var>dim</var> argument is given, operate along this dimension.
</p>
<p><strong>See also:</strong> <a href="#XREFmean">mean</a>, <a href="#XREFmode">mode</a>.
</p></dd></dl>


<span id="XREFmode"></span><dl class="def">
<dt id="index-mode"><span class="category">: </span><span><em></em> <strong>mode</strong> <em>(<var>x</var>)</em><a href='#index-mode' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mode-1"><span class="category">: </span><span><em></em> <strong>mode</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-mode-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mode-2"><span class="category">: </span><span><em>[<var>m</var>, <var>f</var>, <var>c</var>] =</em> <strong>mode</strong> <em>(&hellip;)</em><a href='#index-mode-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the most frequently occurring value in a dataset (mode).
</p>
<p><code>mode</code> determines the frequency of values along the first non-singleton
dimension and returns the value with the highest frequency.  If two, or
more, values have the same frequency <code>mode</code> returns the smallest.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>The return variable <var>f</var> is the number of occurrences of the mode in
the dataset.
</p>
<p>The cell array <var>c</var> contains all of the elements with the maximum
frequency.
</p>
<p><strong>See also:</strong> <a href="#XREFmean">mean</a>, <a href="#XREFmedian">median</a>.
</p></dd></dl>


<p>Using just one number, such as the mean, to represent an entire data set may
not give an accurate picture of the data.  One way to characterize the fit is
to measure the dispersion of the data.  Octave provides several functions for
measuring dispersion.
</p>
<span id="XREFbounds"></span><dl class="def">
<dt id="index-bounds"><span class="category">: </span><span><em>[<var>s</var>, <var>l</var>] =</em> <strong>bounds</strong> <em>(<var>x</var>)</em><a href='#index-bounds' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-bounds-1"><span class="category">: </span><span><em>[<var>s</var>, <var>l</var>] =</em> <strong>bounds</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-bounds-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-bounds-2"><span class="category">: </span><span><em>[<var>s</var>, <var>l</var>] =</em> <strong>bounds</strong> <em>(&hellip;, &quot;nanflag&quot;)</em><a href='#index-bounds-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Return the smallest and largest values of the input data <var>x</var>.
</p>
<p>If <var>x</var> is a vector, the bounds are calculated over the elements of
<var>x</var>.  If <var>x</var> is a matrix, the bounds are calculated for each column.
For a multi-dimensional array, the bounds are calculated over the first
non-singleton dimension.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>The optional argument <code>&quot;nanflag&quot;</code> defaults to <code>&quot;omitnan&quot;</code> which
does not include NaN values in the result.  If the argument
<code>&quot;includenan&quot;</code> is given, and there is a NaN present, then the result
for both smallest (<var>s</var>) and largest (<var>l</var>) elements will be NaN.
</p>
<p>The bounds are a quickly computed measure of the dispersion of a data set,
but are less accurate than <code>iqr</code> if there are outlying data points.
</p>
<p><strong>See also:</strong> <a href="#XREFrange">range</a>, <a href="#XREFiqr">iqr</a>, <a href="#XREFmad">mad</a>, <a href="#XREFstd">std</a>.
</p></dd></dl>


<span id="XREFrange"></span><dl class="def">
<dt id="index-range"><span class="category">: </span><span><em></em> <strong>range</strong> <em>(<var>x</var>)</em><a href='#index-range' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-range-1"><span class="category">: </span><span><em></em> <strong>range</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-range-1' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Return the range, i.e., the difference between the maximum and the minimum
of the input data.
</p>
<p>If <var>x</var> is a vector, the range is calculated over the elements of
<var>x</var>.  If <var>x</var> is a matrix, the range is calculated over each column
of <var>x</var>.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>The range is a quickly computed measure of the dispersion of a data set, but
is less accurate than <code>iqr</code> if there are outlying data points.
</p>
<p><strong>See also:</strong> <a href="#XREFbounds">bounds</a>, <a href="#XREFiqr">iqr</a>, <a href="#XREFmad">mad</a>, <a href="#XREFstd">std</a>.
</p></dd></dl>


<span id="XREFiqr"></span><dl class="def">
<dt id="index-iqr"><span class="category">: </span><span><em><var>Z</var> =</em> <strong>iqr</strong> <em>(<var>x</var>)</em><a href='#index-iqr' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-iqr-1"><span class="category">: </span><span><em><var>Z</var> =</em> <strong>iqr</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-iqr-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-iqr-2"><span class="category">: </span><span><em><var>Z</var> =</em> <strong>iqr</strong> <em>(<var>x</var>, <code>&quot;ALL&quot;</code>)</em><a href='#index-iqr-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Return the interquartile range of <var>x</var>, defined as the distance between
the 25th and 75th percentile values of <var>x</var> calculated using:
   quantile (x, [0.25 0.75])
</p>
<p>If <var>x</var> is a vector, <code>iqr (<var>x</var>)</code> will operate on the data in
<var>x</var>.
</p>
<p>If <var>x</var> is a matrix, <code>iqr (<var>x</var>)</code> will operate independently on
each column in <var>x</var> returning a row vector <var>Z</var>.
</p>
<p>If <var>x</var> is a n-dimensional array, <code>iqr (<var>x</var>)</code> will operate
independently on the first non-singleton dimension in <var>x</var>, returning an
array <var>Z</var> the same shape as <var>x</var> with the non-singleton dimenion
reduced to 1.
</p>
<p>The optional variable <var>dim</var> can be used to force <code>iqr</code> to operate
over the specified dimension.  <var>dim</var> can either be a scalar dimension or
a vector of non-repeating dimensions over which to operate.  In either case
<var>dim</var> must be positive integers.  A vector <var>dim</var> concatenates all
specified dimensions for independent operation by <code>iqr</code>.
</p>
<p>Specifying dimension <code>&quot;ALL&quot;</code> will force <code>iqr</code> to operate
on all elements of <var>x</var>, and is equivalent to <code>iqr (<var>x</var>(:))</code>.
Similarly, specifying a vector dimension including all non-singleton
dimensions of <var>x</var> is equivalent to <code>iqr (<var>x</var>, <code>&quot;ALL&quot;</code>)</code>.
</p>
<p>If <var>x</var> is a scalar, or only singleton dimensions are specified for
<var>dim</var>, the output will be <code>zeros (size (<var>x</var>))</code>.
</p>
<p>As a measure of dispersion, the interquartile range is less affected by
outliers than either <code>range</code> or <code>std</code>.
</p>

<p><strong>See also:</strong> <a href="#XREFbounds">bounds</a>, <a href="#XREFmad">mad</a>, <a href="#XREFrange">range</a>, <a href="#XREFstd">std</a>, <a href="#XREFprctile">prctile</a>, <a href="#XREFquantile">quantile</a>.
</p></dd></dl>


<span id="XREFmad"></span><dl class="def">
<dt id="index-mad"><span class="category">: </span><span><em></em> <strong>mad</strong> <em>(<var>x</var>)</em><a href='#index-mad' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mad-1"><span class="category">: </span><span><em></em> <strong>mad</strong> <em>(<var>x</var>, <var>opt</var>)</em><a href='#index-mad-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-mad-2"><span class="category">: </span><span><em></em> <strong>mad</strong> <em>(<var>x</var>, <var>opt</var>, <var>dim</var>)</em><a href='#index-mad-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the mean or median absolute deviation of the elements of <var>x</var>.
</p>
<p>The mean absolute deviation is defined as
</p>
<div class="example">
<pre class="example"><var>mad</var> = mean (abs (<var>x</var> - mean (<var>x</var>)))
</pre></div>

<p>The median absolute deviation is defined as
</p>
<div class="example">
<pre class="example"><var>mad</var> = median (abs (<var>x</var> - median (<var>x</var>)))
</pre></div>

<p>If <var>x</var> is a matrix, compute <code>mad</code> for each column and return
results in a row vector.  For a multi-dimensional array, the calculation is
done over the first non-singleton dimension.
</p>
<p>The optional argument <var>opt</var> determines whether mean or median absolute
deviation is calculated.  The default is 0 which corresponds to mean
absolute deviation; A value of 1 corresponds to median absolute deviation.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>As a measure of dispersion, <code>mad</code> is less affected by outliers than
<code>std</code>.
</p>
<p><strong>See also:</strong> <a href="#XREFbounds">bounds</a>, <a href="#XREFrange">range</a>, <a href="#XREFiqr">iqr</a>, <a href="#XREFstd">std</a>, <a href="#XREFmean">mean</a>, <a href="#XREFmedian">median</a>.
</p></dd></dl>


<span id="XREFmeansq"></span><dl class="def">
<dt id="index-meansq"><span class="category">: </span><span><em></em> <strong>meansq</strong> <em>(<var>x</var>)</em><a href='#index-meansq' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-meansq-1"><span class="category">: </span><span><em></em> <strong>meansq</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-meansq-1' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the mean square of the elements of the vector <var>x</var>.
</p>
<p>The mean square is defined as
</p>
<div class="example">
<pre class="example">meansq (<var>x</var>) = 1/N SUM_i <var>x</var>(i)^2
</pre></div>

<p>where <em class='math'>N</em> is the length of the <var>x</var> vector.
</p>
<p>If <var>x</var> is a matrix, return a row vector containing the mean square
of each column.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p><strong>See also:</strong> <a href="#XREFvar">var</a>, <a href="#XREFstd">std</a>, <a href="#XREFmoment">moment</a>.
</p></dd></dl>


<span id="XREFstd"></span><dl class="def">
<dt id="index-std"><span class="category">: </span><span><em></em> <strong>std</strong> <em>(<var>x</var>)</em><a href='#index-std' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-std-1"><span class="category">: </span><span><em></em> <strong>std</strong> <em>(<var>x</var>, <var>w</var>)</em><a href='#index-std-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-std-2"><span class="category">: </span><span><em></em> <strong>std</strong> <em>(<var>x</var>, <var>w</var>, <var>dim</var>)</em><a href='#index-std-2' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-std-3"><span class="category">: </span><span><em></em> <strong>std</strong> <em>(<var>x</var>, <var>w</var>, <code>&quot;ALL&quot;</code>)</em><a href='#index-std-3' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the standard deviation of the elements of the vector <var>x</var>.
</p>
<p>The standard deviation is defined as
</p>
<div class="example">
<pre class="example">std (<var>x</var>) = sqrt ( 1/(N-1) SUM_i (<var>x</var>(i) - mean(<var>x</var>))^2 )
</pre></div>

<p>where <em class='math'>N</em> is the number of elements of the <var>x</var> vector.
</p>
<p>If <var>x</var> is an array, compute the standard deviation for each column and
return them in a row vector (or for an n-D array, the result is returned as
an array of dimension 1 x n x m x &hellip;).
</p>
<p>The optional argument <var>w</var> determines the weighting scheme to use.  Valid
values are:
</p>
<dl compact="compact">
<dt><span>0 [default]:</span></dt>
<dd><p>Normalize with <em class='math'>N-1</em>.  This provides the square root of the best
unbiased estimator of the variance.
</p>
</dd>
<dt><span>1:</span></dt>
<dd><p>Normalize with <em class='math'>N</em>. This provides the square root of the second moment
around the mean.
</p>
</dd>
<dt><span>a vector:</span></dt>
<dd><p>Compute the weighted standard deviation with nonnegative scalar weights. The
length of <var>w</var> must be equal to the size of <var>x</var> along dimension
<var>dim</var>.
</p></dd>
</dl>

<p>If <em class='math'>N</em> is equal to 1 the value of <var>W</var> is ignored and
normalization by <em class='math'>N</em> is used.
</p>
<p>The optional variable <var>dim</var> forces <code>std</code> to operate over the
specified dimension.  <var>dim</var> can either be a scalar dimension or a vector
of non-repeating dimensions over which to operate.  Dimensions must be
positive integers, and the standard deviation is calculated over the array
slice defined by <var>dim</var>.
</p>
<p>Specifying dimension <code>&quot;ALL&quot;</code> will force <code>std</code> to operate on all
elements of <var>x</var>, and is equivalent to <code>std (<var>x</var>(:))</code>.
</p>
<p>When <var>dim</var> is a vector or <code>&quot;ALL&quot;</code>, <var>w</var> must be either 0 or 1.
</p>
<p><strong>See also:</strong> <a href="#XREFvar">var</a>, <a href="#XREFbounds">bounds</a>, <a href="#XREFmad">mad</a>, <a href="#XREFrange">range</a>, <a href="#XREFiqr">iqr</a>, <a href="#XREFmean">mean</a>, <a href="#XREFmedian">median</a>.
</p></dd></dl>


<p>In addition to knowing the size of a dispersion it is useful to know the shape
of the data set.  For example, are data points massed to the left or right
of the mean?  Octave provides several common measures to describe the shape
of the data set.  Octave can also calculate moments allowing arbitrary shape
measures to be developed.
</p>
<span id="XREFvar"></span><dl class="def">
<dt id="index-var"><span class="category">: </span><span><em></em> <strong>var</strong> <em>(<var>x</var>)</em><a href='#index-var' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-var-1"><span class="category">: </span><span><em></em> <strong>var</strong> <em>(<var>x</var>, <var>w</var>)</em><a href='#index-var-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-var-2"><span class="category">: </span><span><em></em> <strong>var</strong> <em>(<var>x</var>, <var>w</var>, <var>dim</var>)</em><a href='#index-var-2' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-var-3"><span class="category">: </span><span><em></em> <strong>var</strong> <em>(<var>x</var>, <var>w</var>, <code>&quot;ALL&quot;</code>)</em><a href='#index-var-3' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the variance of the elements of the vector <var>x</var>.
</p>
<p>The variance is defined as
</p>
<div class="example">
<pre class="example">var (<var>x</var>) = 1/(N-1) SUM_i (<var>x</var>(i) - mean(<var>x</var>))^2
</pre></div>

<p>where <em class='math'>N</em> is the length of the <var>x</var> vector.
</p>
<p>If <var>x</var> is an array, compute the variance for each column and return
them in a row vector (or for an n-D array, the result is returned as
an array of dimension 1 x n x m x &hellip;).
</p>
<p>The optional argument <var>w</var> determines the weighting scheme to use.  Valid
values are
</p>
<dl compact="compact">
<dt><span>0 [default]:</span></dt>
<dd><p>Normalize with <em class='math'>N-1</em>.  This provides the square root of the best
unbiased estimator of the variance.
</p>
</dd>
<dt><span>1:</span></dt>
<dd><p>Normalize with <em class='math'>N</em>, this provides the square root of the second moment
around the mean
</p>
</dd>
<dt><span>a vector:</span></dt>
<dd><p>Compute the weighted variance with nonnegative scalar weights.  The length of
<var>w</var> must be equal to the size of <var>x</var> along dimension <var>dim</var>.
</p></dd>
</dl>

<p>If <em class='math'>N</em> is equal to 1 the value of <var>W</var> is ignored and
normalization by <em class='math'>N</em> is used.
</p>
<p>The optional variable <var>dim</var> forces <code>var</code> to operate over the
specified dimension.  <var>dim</var> can either be a scalar dimension or a vector
of non-repeating dimensions over which to operate.  Dimensions must be
positive integers, and the variance is calculated over the array slice
defined by <var>dim</var>.
</p>
<p>Specifying dimension <code>&quot;ALL&quot;</code> will force <code>var</code> to operate on all
elements of <var>x</var>, and is equivalent to <code>var (<var>x</var>(:))</code>.
</p>
<p>When <var>dim</var> is a vector or <code>&quot;ALL&quot;</code>, <var>w</var> must be either 0 or 1.
</p>
<p><strong>See also:</strong> <a href="Correlation-and-Regression-Analysis.html#XREFcov">cov</a>, <a href="#XREFstd">std</a>, <a href="#XREFskewness">skewness</a>, <a href="#XREFkurtosis">kurtosis</a>, <a href="#XREFmoment">moment</a>.
</p></dd></dl>


<span id="XREFskewness"></span><dl class="def">
<dt id="index-skewness"><span class="category">: </span><span><em></em> <strong>skewness</strong> <em>(<var>x</var>)</em><a href='#index-skewness' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-skewness-1"><span class="category">: </span><span><em></em> <strong>skewness</strong> <em>(<var>x</var>, <var>flag</var>)</em><a href='#index-skewness-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-skewness-2"><span class="category">: </span><span><em></em> <strong>skewness</strong> <em>(<var>x</var>, <var>flag</var>, <var>dim</var>)</em><a href='#index-skewness-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the sample skewness of the elements of <var>x</var>.
</p>
<p>The sample skewness is defined as
</p>
<div class="example">
<pre class="example">               mean ((<var>x</var> - mean (<var>x</var>)).^3)
skewness (<var>X</var>) = ------------------------.
                      std (<var>x</var>).^3
</pre></div>


<p>The optional argument <var>flag</var> controls which normalization is used.
If <var>flag</var> is equal to 1 (default value, used when <var>flag</var> is omitted
or empty), return the sample skewness as defined above.  If <var>flag</var> is
equal to 0, return the adjusted skewness coefficient instead:
</p>
<div class="example">
<pre class="example">                  sqrt (N*(N-1))   mean ((<var>x</var> - mean (<var>x</var>)).^3)
skewness (<var>X</var>, 0) = -------------- * ------------------------.
                      (N - 2)             std (<var>x</var>).^3
</pre></div>

<p>where <em class='math'>N</em> is the length of the <var>x</var> vector.
</p>
<p>The adjusted skewness coefficient is obtained by replacing the sample second
and third central moments by their bias-corrected versions.
</p>
<p>If <var>x</var> is a matrix, or more generally a multi-dimensional array, return
the skewness along the first non-singleton dimension.  If the optional
<var>dim</var> argument is given, operate along this dimension.
</p>

<p><strong>See also:</strong> <a href="#XREFvar">var</a>, <a href="#XREFkurtosis">kurtosis</a>, <a href="#XREFmoment">moment</a>.
</p></dd></dl>


<span id="XREFkurtosis"></span><dl class="def">
<dt id="index-kurtosis"><span class="category">: </span><span><em></em> <strong>kurtosis</strong> <em>(<var>x</var>)</em><a href='#index-kurtosis' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-kurtosis-1"><span class="category">: </span><span><em></em> <strong>kurtosis</strong> <em>(<var>x</var>, <var>flag</var>)</em><a href='#index-kurtosis-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-kurtosis-2"><span class="category">: </span><span><em></em> <strong>kurtosis</strong> <em>(<var>x</var>, <var>flag</var>, <var>dim</var>)</em><a href='#index-kurtosis-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the sample kurtosis of the elements of <var>x</var>.
</p>
<p>The sample kurtosis is defined as
</p>
<div class="example">
<pre class="example">     mean ((<var>x</var> - mean (<var>x</var>)).^4)
k1 = ------------------------
            std (<var>x</var>).^4
</pre></div>


<p>The optional argument <var>flag</var> controls which normalization is used.
If <var>flag</var> is equal to 1 (default value, used when <var>flag</var> is omitted
or empty), return the sample kurtosis as defined above.  If <var>flag</var> is
equal to 0, return the <span class="nolinebreak">&quot;bias-corrected&quot;</span><!-- /@w --> kurtosis coefficient instead:
</p>
<div class="example">
<pre class="example">              N - 1
k0 = 3 + -------------- * ((N + 1) * k1 - 3 * (N - 1))
         (N - 2)(N - 3)
</pre></div>

<p>where <em class='math'>N</em> is the length of the <var>x</var> vector.
</p>
<p>The bias-corrected kurtosis coefficient is obtained by replacing the sample
second and fourth central moments by their unbiased versions.  It is an
unbiased estimate of the population kurtosis for normal populations.
</p>
<p>If <var>x</var> is a matrix, or more generally a multi-dimensional array, return
the kurtosis along the first non-singleton dimension.  If the optional
<var>dim</var> argument is given, operate along this dimension.
</p>

<p><strong>See also:</strong> <a href="#XREFvar">var</a>, <a href="#XREFskewness">skewness</a>, <a href="#XREFmoment">moment</a>.
</p></dd></dl>


<span id="XREFmoment"></span><dl class="def">
<dt id="index-moment"><span class="category">: </span><span><em></em> <strong>moment</strong> <em>(<var>x</var>, <var>p</var>)</em><a href='#index-moment' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-moment-1"><span class="category">: </span><span><em></em> <strong>moment</strong> <em>(<var>x</var>, <var>p</var>, <var>type</var>)</em><a href='#index-moment-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-moment-2"><span class="category">: </span><span><em></em> <strong>moment</strong> <em>(<var>x</var>, <var>p</var>, <var>dim</var>)</em><a href='#index-moment-2' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-moment-3"><span class="category">: </span><span><em></em> <strong>moment</strong> <em>(<var>x</var>, <var>p</var>, <var>type</var>, <var>dim</var>)</em><a href='#index-moment-3' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-moment-4"><span class="category">: </span><span><em></em> <strong>moment</strong> <em>(<var>x</var>, <var>p</var>, <var>dim</var>, <var>type</var>)</em><a href='#index-moment-4' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Compute the <var>p</var>-th central moment of the vector <var>x</var>.
</p>
<p>The <var>p</var>-th central moment of <var>x</var> is defined as:
</p>

<div class="example">
<pre class="example">1/N SUM_i (<var>x</var>(i) - mean(<var>x</var>))^<var>p</var>
</pre></div>

<p>where <em class='math'>N</em> is the length of the <var>x</var> vector.
</p>

<p>If <var>x</var> is a matrix, return the row vector containing the <var>p</var>-th
central moment of each column.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>The optional string <var>type</var> specifies the type of moment to be computed.
Valid options are:
</p>
<dl compact="compact">
<dt><span><code>&quot;c&quot;</code></span></dt>
<dd><p>Central Moment (default).
</p>
</dd>
<dt><span><code>&quot;a&quot;</code></span></dt>
<dt><span><code>&quot;ac&quot;</code></span></dt>
<dd><p>Absolute Central Moment.  The moment about the mean ignoring sign
defined as
</p>
<div class="example">
<pre class="example">1/N SUM_i (abs (<var>x</var>(i) - mean(<var>x</var>)))^<var>p</var>
</pre></div>


</dd>
<dt><span><code>&quot;r&quot;</code></span></dt>
<dd><p>Raw Moment.  The moment about zero defined as
</p>

<div class="example">
<pre class="example">moment (<var>x</var>) = 1/N SUM_i <var>x</var>(i)^<var>p</var>
</pre></div>


</dd>
<dt><span><code>&quot;ar&quot;</code></span></dt>
<dd><p>Absolute Raw Moment.  The moment about zero ignoring sign defined as
</p>
<div class="example">
<pre class="example">1/N SUM_i ( abs (<var>x</var>(i)) )^<var>p</var>
</pre></div>

</dd>
</dl>

<p>If both <var>type</var> and <var>dim</var> are given they may appear in any order.
</p>
<p><strong>See also:</strong> <a href="#XREFvar">var</a>, <a href="#XREFskewness">skewness</a>, <a href="#XREFkurtosis">kurtosis</a>.
</p></dd></dl>


<span id="XREFquantile"></span><dl class="def">
<dt id="index-quantile"><span class="category">: </span><span><em><var>q</var> =</em> <strong>quantile</strong> <em>(<var>x</var>)</em><a href='#index-quantile' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-quantile-1"><span class="category">: </span><span><em><var>q</var> =</em> <strong>quantile</strong> <em>(<var>x</var>, <var>p</var>)</em><a href='#index-quantile-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-quantile-2"><span class="category">: </span><span><em><var>q</var> =</em> <strong>quantile</strong> <em>(<var>x</var>, <var>p</var>, <var>dim</var>)</em><a href='#index-quantile-2' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-quantile-3"><span class="category">: </span><span><em><var>q</var> =</em> <strong>quantile</strong> <em>(<var>x</var>, <var>p</var>, <var>dim</var>, <var>method</var>)</em><a href='#index-quantile-3' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>For a sample, <var>x</var>, calculate the quantiles, <var>q</var>, corresponding to
the cumulative probability values in <var>p</var>.  All non-numeric values (NaNs)
of <var>x</var> are ignored.
</p>
<p>If <var>x</var> is a matrix, compute the quantiles for each column and
return them in a matrix, such that the i-th row of <var>q</var> contains
the <var>p</var>(i)th quantiles of each column of <var>x</var>.
</p>
<p>If <var>p</var> is unspecified, return the quantiles for
<code>[0.00 0.25 0.50 0.75 1.00]</code>.
The optional argument <var>dim</var> determines the dimension along which
the quantiles are calculated.  If <var>dim</var> is omitted it defaults to
the first non-singleton dimension.
</p>
<p>The methods available to calculate sample quantiles are the nine methods
used by R (<a href="https://www.r-project.org/">https://www.r-project.org/</a>).  The default value is
<var>method</var>&nbsp;=&nbsp;5<!-- /@w -->.
</p>
<p>Discontinuous sample quantile methods 1, 2, and 3
</p>
<ol>
<li> Method 1: Inverse of empirical distribution function.

</li><li> Method 2: Similar to method 1 but with averaging at discontinuities.

</li><li> Method 3: SAS definition: nearest even order statistic.
</li></ol>

<p>Continuous sample quantile methods 4 through 9, where
<var>p</var>(k)
is the linear
interpolation function respecting each method&rsquo;s representative cdf.
</p>
<ol start="4">
<li> Method 4:
<var>p</var>(k) = k / N.
That is, linear interpolation of the empirical cdf, where <em class='math'>N</em> is the
length of <var>P</var>.

</li><li> Method 5:
<var>p</var>(k) = (k - 0.5) / N.
That is, a piecewise linear function where the knots are the values midway
through the steps of the empirical cdf.

</li><li> Method 6:
<var>p</var>(k) = k / (N + 1).

</li><li> Method 7:
<var>p</var>(k) = (k - 1) / (N - 1).

</li><li> Method 8:
<var>p</var>(k) = (k - 1/3) / (N + 1/3).
The resulting quantile estimates are approximately median-unbiased
regardless of the distribution of <var>x</var>.

</li><li> Method 9:
<var>p</var>(k) = (k - 3/8) / (N + 1/4).
The resulting quantile estimates are approximately unbiased for the
expected order statistics if <var>x</var> is normally distributed.
</li></ol>

<p>Hyndman and Fan (1996) recommend method 8.  Maxima, S, and R
(versions prior to 2.0.0) use 7 as their default.  Minitab and SPSS
use method 6.  <small>MATLAB</small> uses method 5.
</p>
<p>References:
</p>
<ul>
<li> Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
The New S Language.  Wadsworth &amp; Brooks/Cole.

</li><li> Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in
statistical packages, American Statistician, 50, 361&ndash;365.

</li><li> R: A Language and Environment for Statistical Computing;
<a href="https://cran.r-project.org/doc/manuals/fullrefman.pdf">https://cran.r-project.org/doc/manuals/fullrefman.pdf</a>.
</li></ul>

<p>Examples:
</p>
<div class="example">
<pre class="example">x = randi (1000, [10, 1]);  # Create empirical data in range 1-1000
q = quantile (x, [0, 1]);   # Return minimum, maximum of distribution
q = quantile (x, [0.25 0.5 0.75]); # Return quartiles of distribution
</pre></div>

<p><strong>See also:</strong> <a href="#XREFprctile">prctile</a>.
</p></dd></dl>


<span id="XREFprctile"></span><dl class="def">
<dt id="index-prctile"><span class="category">: </span><span><em><var>q</var> =</em> <strong>prctile</strong> <em>(<var>x</var>)</em><a href='#index-prctile' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-prctile-1"><span class="category">: </span><span><em><var>q</var> =</em> <strong>prctile</strong> <em>(<var>x</var>, <var>p</var>)</em><a href='#index-prctile-1' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-prctile-2"><span class="category">: </span><span><em><var>q</var> =</em> <strong>prctile</strong> <em>(<var>x</var>, <var>p</var>, <var>dim</var>)</em><a href='#index-prctile-2' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>For a sample <var>x</var>, compute the quantiles, <var>q</var>, corresponding
to the cumulative probability values, <var>p</var>, in percent.
</p>
<p>If <var>x</var> is a matrix, compute the percentiles for each column and return
them in a matrix, such that the i-th row of <var>q</var> contains the
<var>p</var>(i)th percentiles of each column of <var>x</var>.
</p>
<p>If <var>p</var> is unspecified, return the quantiles for <code>[0 25 50 75 100]</code>.
</p>
<p>The optional argument <var>dim</var> determines the dimension along which the
percentiles are calculated.  If <var>dim</var> is omitted it defaults to the
first non-singleton dimension.
</p>
<p>Programming Note: All non-numeric values (NaNs) of <var>x</var> are ignored.
</p>
<p><strong>See also:</strong> <a href="#XREFquantile">quantile</a>.
</p></dd></dl>


<p>A summary view of a data set can be generated quickly with the
<code>statistics</code> function.
</p>
<span id="XREFstatistics"></span><dl class="def">
<dt id="index-statistics"><span class="category">: </span><span><em></em> <strong>statistics</strong> <em>(<var>x</var>)</em><a href='#index-statistics' class='copiable-anchor'> &para;</a></span></dt>
<dt id="index-statistics-1"><span class="category">: </span><span><em></em> <strong>statistics</strong> <em>(<var>x</var>, <var>dim</var>)</em><a href='#index-statistics-1' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Return a vector with the minimum, first quartile, median, third quartile,
maximum, mean, standard deviation, skewness, and kurtosis of the elements of
the vector <var>x</var>.
</p>
<p>If <var>x</var> is a matrix, calculate statistics over the first non-singleton
dimension.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p><strong>See also:</strong> <a href="Utility-Functions.html#XREFmin">min</a>, <a href="Utility-Functions.html#XREFmax">max</a>, <a href="#XREFmedian">median</a>, <a href="#XREFmean">mean</a>, <a href="#XREFstd">std</a>, <a href="#XREFskewness">skewness</a>, <a href="#XREFkurtosis">kurtosis</a>.
</p></dd></dl>


</div>
<hr>
<div class="header">
<p>
Next: <a href="Statistics-on-Sliding-Windows-of-Data.html">Statistics on Sliding Windows of Data</a>, Up: <a href="Statistics.html">Statistics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>