File: Basic-Statistical-Functions.html

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (285 lines) | stat: -rw-r--r-- 13,095 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Basic Statistical Functions (GNU Octave (version 6.2.0))</title>

<meta name="description" content="Basic Statistical Functions (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Basic Statistical Functions (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<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="Correlation-and-Regression-Analysis.html" rel="next" title="Correlation and Regression Analysis">
<link href="Statistics-on-Sliding-Windows-of-Data.html" rel="prev" title="Statistics on Sliding Windows of 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>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<span id="Basic-Statistical-Functions"></span><div class="header">
<p>
Next: <a href="Correlation-and-Regression-Analysis.html" accesskey="n" rel="next">Correlation and Regression Analysis</a>, Previous: <a href="Statistics-on-Sliding-Windows-of-Data.html" accesskey="p" rel="prev">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="Basic-Statistical-Functions-1"></span><h3 class="section">26.3 Basic Statistical Functions</h3>

<p>Octave supports various helpful statistical functions.  Many are useful as
initial steps to prepare a data set for further analysis.  Others provide
different measures from those of the basic descriptive statistics.
</p>
<span id="XREFcenter"></span><dl>
<dt id="index-center">: <em></em> <strong>center</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-center-1">: <em></em> <strong>center</strong> <em>(<var>x</var>, <var>dim</var>)</em></dt>
<dd><p>Center data by subtracting its mean.
</p>
<p>If <var>x</var> is a vector, subtract its mean.
</p>
<p>If <var>x</var> is a matrix, do the above for each column.
</p>
<p>If the optional argument <var>dim</var> is given, operate along this dimension.
</p>
<p>Programming Note: <code>center</code> has obvious application for normalizing
statistical data.  It is also useful for improving the precision of general
numerical calculations.  Whenever there is a large value that is common
to a batch of data, the mean can be subtracted off, the calculation
performed, and then the mean added back to obtain the final answer.
</p>
<p><strong>See also:</strong> <a href="#XREFzscore">zscore</a>.
</p></dd></dl>


<span id="XREFzscore"></span><dl>
<dt id="index-zscore">: <em><var>z</var> =</em> <strong>zscore</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-zscore-1">: <em><var>z</var> =</em> <strong>zscore</strong> <em>(<var>x</var>, <var>opt</var>)</em></dt>
<dt id="index-zscore-2">: <em><var>z</var> =</em> <strong>zscore</strong> <em>(<var>x</var>, <var>opt</var>, <var>dim</var>)</em></dt>
<dt id="index-zscore-3">: <em>[<var>z</var>, <var>mu</var>, <var>sigma</var>] =</em> <strong>zscore</strong> <em>(&hellip;)</em></dt>
<dd><p>Compute the Z score of <var>x</var>.
</p>
<p>If <var>x</var> is a vector, subtract its mean and divide by its standard
deviation.  If the standard deviation is zero, divide by 1 instead.
</p>
<p>The optional parameter <var>opt</var> determines the normalization to use when
computing the standard deviation and has the same definition as the
corresponding parameter for <code>std</code>.
</p>
<p>If <var>x</var> is a matrix, calculate along the first non-singleton dimension.
If the third optional argument <var>dim</var> is given, operate along this
dimension.
</p>
<p>The optional outputs <var>mu</var> and <var>sigma</var> contain the mean and standard
deviation.
</p>

<p><strong>See also:</strong> <a href="Descriptive-Statistics.html#XREFmean">mean</a>, <a href="Descriptive-Statistics.html#XREFstd">std</a>, <a href="#XREFcenter">center</a>.
</p></dd></dl>


<span id="XREFhistc"></span><dl>
<dt id="index-histc">: <em><var>n</var> =</em> <strong>histc</strong> <em>(<var>x</var>, <var>edges</var>)</em></dt>
<dt id="index-histc-1">: <em><var>n</var> =</em> <strong>histc</strong> <em>(<var>x</var>, <var>edges</var>, <var>dim</var>)</em></dt>
<dt id="index-histc-2">: <em>[<var>n</var>, <var>idx</var>] =</em> <strong>histc</strong> <em>(&hellip;)</em></dt>
<dd><p>Compute histogram counts.
</p>
<p>When <var>x</var> is a vector, the function counts the number of elements of
<var>x</var> that fall in the histogram bins defined by <var>edges</var>.  This
must be a vector of monotonically increasing values that define the edges
of the histogram bins.
<code><var>n</var>(k)</code>
contains the number of elements in <var>x</var> for which
<code><var>edges</var>(k) &lt;= <var>x</var> &lt; <var>edges</var>(k+1)</code>.
The final element of <var>n</var> contains the number of elements of <var>x</var>
exactly equal to the last element of <var>edges</var>.
</p>
<p>When <var>x</var> is an <em>N</em>-dimensional array, the computation is carried
out along dimension <var>dim</var>.  If not specified <var>dim</var> defaults to the
first non-singleton dimension.
</p>
<p>When a second output argument is requested an index matrix is also returned.
The <var>idx</var> matrix has the same size as <var>x</var>.  Each element of
<var>idx</var> contains the index of the histogram bin in which the
corresponding element of <var>x</var> was counted.
</p>
<p><strong>See also:</strong> <a href="Two_002dDimensional-Plots.html#XREFhist">hist</a>.
</p></dd></dl>


<p><code>unique</code> function documented at <a href="Sets.html#XREFunique">unique</a> is often
useful for statistics.
</p>
<span id="XREFnchoosek"></span><dl>
<dt id="index-nchoosek">: <em><var>c</var> =</em> <strong>nchoosek</strong> <em>(<var>n</var>, <var>k</var>)</em></dt>
<dt id="index-nchoosek-1">: <em><var>c</var> =</em> <strong>nchoosek</strong> <em>(<var>set</var>, <var>k</var>)</em></dt>
<dd>
<p>Compute the binomial coefficient of <var>n</var> or list all possible
combinations of a <var>set</var> of items.
</p>
<p>If <var>n</var> is a scalar then calculate the binomial coefficient
of <var>n</var> and <var>k</var> which is defined as
</p>
<div class="example">
<pre class="example"> /   \
 | n |    n (n-1) (n-2) &hellip; (n-k+1)       n!
 |   |  = ------------------------- =  ---------
 | k |               k!                k! (n-k)!
 \   /
</pre></div>

<p>This is the number of combinations of <var>n</var> items taken in groups of
size <var>k</var>.
</p>
<p>If the first argument is a vector, <var>set</var>, then generate all
combinations of the elements of <var>set</var>, taken <var>k</var> at a time, with
one row per combination.  The result <var>c</var> has <var>k</var> columns and
<code>nchoosek&nbsp;(length&nbsp;(<var>set</var>),&nbsp;<var>k</var>)</code><!-- /@w --> rows.
</p>
<p>For example:
</p>
<p>How many ways can three items be grouped into pairs?
</p>
<div class="example">
<pre class="example">nchoosek (3, 2)
   &rArr; 3
</pre></div>

<p>What are the possible pairs?
</p>
<div class="example">
<pre class="example">nchoosek (1:3, 2)
   &rArr;  1   2
       1   3
       2   3
</pre></div>

<p>Programming Note: When calculating the binomial coefficient <code>nchoosek</code>
works only for non-negative, integer arguments.  Use <code>bincoeff</code> for
non-integer and negative scalar arguments, or for computing many binomial
coefficients at once with vector inputs for <var>n</var> or <var>k</var>.
</p>

<p><strong>See also:</strong> <a href="Special-Functions.html#XREFbincoeff">bincoeff</a>, <a href="#XREFperms">perms</a>.
</p></dd></dl>


<span id="XREFperms"></span><dl>
<dt id="index-perms">: <em></em> <strong>perms</strong> <em>(<var>v</var>)</em></dt>
<dd><p>Generate all permutations of vector <var>v</var> with one row per permutation.
</p>
<p>Results are returned in inverse lexicographic order.  The result has size
<code>factorial (<var>n</var>) * <var>n</var></code>, where <var>n</var> is the length of
<var>v</var>.  Any repetitions are included in the output.  To generate just the
unique permutations use <code>unique (perms (<var>v</var>), &quot;rows&quot;)(end:-1:1,:)</code>.
</p>
<p>Example
</p>
<div class="example">
<pre class="example">perms ([1, 2, 3])
&rArr;
  3   2   1
  3   1   2
  2   3   1
  2   1   3
  1   3   2
  1   2   3
</pre></div>

<p>Programming Note: The maximum length of <var>v</var> should be less than or
equal to 10 to limit memory consumption.
</p>
<p><strong>See also:</strong> <a href="Rearranging-Matrices.html#XREFpermute">permute</a>, <a href="Special-Utility-Matrices.html#XREFrandperm">randperm</a>, <a href="#XREFnchoosek">nchoosek</a>.
</p></dd></dl>


<span id="XREFranks"></span><dl>
<dt id="index-ranks">: <em></em> <strong>ranks</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-ranks-1">: <em></em> <strong>ranks</strong> <em>(<var>x</var>, <var>dim</var>)</em></dt>
<dt id="index-ranks-2">: <em></em> <strong>ranks</strong> <em>(<var>x</var>, <var>dim</var>, <var>rtype</var>)</em></dt>
<dd><p>Return the ranks (in the sense of order statistics) of <var>x</var> along the
first non-singleton dimension adjusted for ties.
</p>
<p>If the optional <var>dim</var> argument is given, operate along this dimension.
</p>
<p>The optional parameter <var>rtype</var> determines how ties are handled.  All
examples below assume an input of <code>[ 1, 2, 2, 4 ]</code>.
</p>
<dl compact="compact">
<dt>0 or <code>&quot;fractional&quot;</code> (default) for fractional ranking (1, 2.5,</dt>
<dd><p>2.5, 4);
</p>
</dd>
<dt>1 or <code>&quot;competition&quot;</code> for competition ranking (1, 2, 2, 4);</dt>
<dt>2 or <code>&quot;modified&quot;</code> for modified competition ranking (1, 3, 3, 4);</dt>
<dt>3 or <code>&quot;ordinal&quot;</code> for ordinal ranking (1, 2, 3, 4);</dt>
<dt>4 or <code>&quot;dense&quot;</code> for dense ranking (1, 2, 2, 3).</dt>
</dl>


<p><strong>See also:</strong> <a href="Correlation-and-Regression-Analysis.html#XREFspearman">spearman</a>, <a href="Correlation-and-Regression-Analysis.html#XREFkendall">kendall</a>.
</p></dd></dl>


<span id="XREFrun_005fcount"></span><dl>
<dt id="index-run_005fcount">: <em></em> <strong>run_count</strong> <em>(<var>x</var>, <var>n</var>)</em></dt>
<dt id="index-run_005fcount-1">: <em></em> <strong>run_count</strong> <em>(<var>x</var>, <var>n</var>, <var>dim</var>)</em></dt>
<dd><p>Count the upward runs along the first non-singleton dimension of <var>x</var>
of length 1, 2, &hellip;, <var>n</var>-1 and greater than or equal to <var>n</var>.
</p>
<p>If the optional argument <var>dim</var> is given then operate along this
dimension.
</p>
<p><strong>See also:</strong> <a href="#XREFrunlength">runlength</a>.
</p></dd></dl>


<span id="XREFrunlength"></span><dl>
<dt id="index-runlength">: <em>count =</em> <strong>runlength</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-runlength-1">: <em>[count, value] =</em> <strong>runlength</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Find the lengths of all sequences of common values.
</p>
<p><var>count</var> is a vector with the lengths of each repeated value.
</p>
<p>The optional output <var>value</var> contains the value that was repeated in
the sequence.
</p>
<div class="example">
<pre class="example">runlength ([2, 2, 0, 4, 4, 4, 0, 1, 1, 1, 1])
&rArr;   2   1   3   1   4
</pre></div>

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


<hr>
<div class="header">
<p>
Next: <a href="Correlation-and-Regression-Analysis.html" accesskey="n" rel="next">Correlation and Regression Analysis</a>, Previous: <a href="Statistics-on-Sliding-Windows-of-Data.html" accesskey="p" rel="prev">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>



</body>
</html>