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
|
<!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>Correlation and Regression Analysis (GNU Octave (version 6.2.0))</title>
<meta name="description" content="Correlation and Regression Analysis (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Correlation and Regression Analysis (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="Distributions.html" rel="next" title="Distributions">
<link href="Basic-Statistical-Functions.html" rel="prev" title="Basic Statistical Functions">
<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="Correlation-and-Regression-Analysis"></span><div class="header">
<p>
Next: <a href="Distributions.html" accesskey="n" rel="next">Distributions</a>, Previous: <a href="Basic-Statistical-Functions.html" accesskey="p" rel="prev">Basic Statistical Functions</a>, Up: <a href="Statistics.html" accesskey="u" rel="up">Statistics</a> [<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="Correlation-and-Regression-Analysis-1"></span><h3 class="section">26.4 Correlation and Regression Analysis</h3>
<span id="XREFcov"></span><dl>
<dt id="index-cov">: <em></em> <strong>cov</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-cov-1">: <em></em> <strong>cov</strong> <em>(<var>x</var>, <var>opt</var>)</em></dt>
<dt id="index-cov-2">: <em></em> <strong>cov</strong> <em>(<var>x</var>, <var>y</var>)</em></dt>
<dt id="index-cov-3">: <em></em> <strong>cov</strong> <em>(<var>x</var>, <var>y</var>, <var>opt</var>)</em></dt>
<dd><p>Compute the covariance matrix.
</p>
<p>If each row of <var>x</var> and <var>y</var> is an observation, and each column is
a variable, then the (<var>i</var>, <var>j</var><span class="nolinebreak">)-th</span><!-- /@w --> entry of
<code>cov (<var>x</var>, <var>y</var>)</code> is the covariance between the <var>i</var>-th
variable in <var>x</var> and the <var>j</var>-th variable in <var>y</var>.
</p>
<div class="example">
<pre class="example">cov (<var>x</var>) = 1/(N-1) * SUM_i (<var>x</var>(i) - mean(<var>x</var>)) * (<var>y</var>(i) - mean(<var>y</var>))
</pre></div>
<p>where <em>N</em> is the length of the <var>x</var> and <var>y</var> vectors.
</p>
<p>If called with one argument, compute <code>cov (<var>x</var>, <var>x</var>)</code>, the
covariance between the columns of <var>x</var>.
</p>
<p>The argument <var>opt</var> determines the type of normalization to use.
Valid values are
</p>
<dl compact="compact">
<dt>0:</dt>
<dd><p>normalize with <em>N-1</em>, provides the best unbiased estimator of the
covariance [default]
</p>
</dd>
<dt>1:</dt>
<dd><p>normalize with <em>N</em>, this provides the second moment around the mean
</p></dd>
</dl>
<p>Compatibility Note:: Octave always treats rows of <var>x</var> and <var>y</var>
as multivariate random variables.
For two inputs, however, <small>MATLAB</small> treats <var>x</var> and <var>y</var> as two
univariate distributions regardless of their shapes, and will calculate
<code>cov ([<var>x</var>(:), <var>y</var>(:)])</code> whenever the number of elements in
<var>x</var> and <var>y</var> are equal. This will result in a 2x2 matrix.
Code relying on <small>MATLAB</small>’s definition will need to be changed when
running in Octave.
</p>
<p><strong>See also:</strong> <a href="#XREFcorr">corr</a>.
</p></dd></dl>
<span id="XREFcorr"></span><dl>
<dt id="index-corr">: <em></em> <strong>corr</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-corr-1">: <em></em> <strong>corr</strong> <em>(<var>x</var>, <var>y</var>)</em></dt>
<dd><p>Compute matrix of correlation coefficients.
</p>
<p>If each row of <var>x</var> and <var>y</var> is an observation and each column is
a variable, then the (<var>i</var>, <var>j</var><span class="nolinebreak">)-th</span><!-- /@w --> entry of
<code>corr (<var>x</var>, <var>y</var>)</code> is the correlation between the
<var>i</var>-th variable in <var>x</var> and the <var>j</var>-th variable in <var>y</var>.
</p>
<div class="example">
<pre class="example">corr (<var>x</var>,<var>y</var>) = cov (<var>x</var>,<var>y</var>) / (std (<var>x</var>) * std (<var>y</var>))
</pre></div>
<p>If called with one argument, compute <code>corr (<var>x</var>, <var>x</var>)</code>,
the correlation between the columns of <var>x</var>.
</p>
<p><strong>See also:</strong> <a href="#XREFcov">cov</a>.
</p></dd></dl>
<span id="XREFcorrcoef"></span><dl>
<dt id="index-corrcoef">: <em><var>r</var> =</em> <strong>corrcoef</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-corrcoef-1">: <em><var>r</var> =</em> <strong>corrcoef</strong> <em>(<var>x</var>, <var>y</var>)</em></dt>
<dt id="index-corrcoef-2">: <em><var>r</var> =</em> <strong>corrcoef</strong> <em>(…, <var>param</var>, <var>value</var>, …)</em></dt>
<dt id="index-corrcoef-3">: <em>[<var>r</var>, <var>p</var>] =</em> <strong>corrcoef</strong> <em>(…)</em></dt>
<dt id="index-corrcoef-4">: <em>[<var>r</var>, <var>p</var>, <var>lci</var>, <var>hci</var>] =</em> <strong>corrcoef</strong> <em>(…)</em></dt>
<dd><p>Compute a matrix of correlation coefficients.
</p>
<p><var>x</var> is an array where each column contains a variable and each row is
an observation.
</p>
<p>If a second input <var>y</var> (of the same size as <var>x</var>) is given then
calculate the correlation coefficients between <var>x</var> and <var>y</var>.
</p>
<p><var>param</var>, <var>value</var> are optional pairs of parameters and values which
modify the calculation. Valid options are:
</p>
<dl compact="compact">
<dt><code>"alpha"</code></dt>
<dd><p>Confidence level used for the bounds of the confidence interval, <var>lci</var>
and <var>hci</var>. Default is 0.05, i.e., 95% confidence interval.
</p>
</dd>
<dt><code>"rows"</code></dt>
<dd><p>Determine processing of NaN values. Acceptable values are <code>"all"</code>,
<code>"complete"</code>, and <code>"pairwise"</code>. Default is <code>"all"</code>.
With <code>"complete"</code>, only the rows without NaN values are considered.
With <code>"pairwise"</code>, the selection of NaN-free rows is made for each
pair of variables.
</p></dd>
</dl>
<p>Output <var>r</var> is a matrix of Pearson’s product moment correlation
coefficients for each pair of variables.
</p>
<p>Output <var>p</var> is a matrix of pair-wise p-values testing for the null
hypothesis of a correlation coefficient of zero.
</p>
<p>Outputs <var>lci</var> and <var>hci</var> are matrices containing, respectively, the
lower and higher bounds of the 95% confidence interval of each correlation
coefficient.
</p>
<p><strong>See also:</strong> <a href="#XREFcorr">corr</a>, <a href="#XREFcov">cov</a>.
</p></dd></dl>
<span id="XREFspearman"></span><dl>
<dt id="index-spearman">: <em></em> <strong>spearman</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-spearman-1">: <em></em> <strong>spearman</strong> <em>(<var>x</var>, <var>y</var>)</em></dt>
<dd><span id="index-Spearman_0027s-Rho"></span>
<p>Compute Spearman’s rank correlation coefficient
<var>rho</var>.
</p>
<p>For two data vectors <var>x</var> and <var>y</var>, Spearman’s
<var>rho</var>
is the correlation coefficient of the ranks of <var>x</var> and <var>y</var>.
</p>
<p>If <var>x</var> and <var>y</var> are drawn from independent distributions,
<var>rho</var>
has zero mean and variance
<code>1 / (N - 1)</code>,
where <em>N</em> is the length of the <var>x</var> and <var>y</var> vectors, and is
asymptotically normally distributed.
</p>
<p><code>spearman (<var>x</var>)</code> is equivalent to
<code>spearman (<var>x</var>, <var>x</var>)</code>.
</p>
<p><strong>See also:</strong> <a href="Basic-Statistical-Functions.html#XREFranks">ranks</a>, <a href="#XREFkendall">kendall</a>.
</p></dd></dl>
<span id="XREFkendall"></span><dl>
<dt id="index-kendall">: <em></em> <strong>kendall</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-kendall-1">: <em></em> <strong>kendall</strong> <em>(<var>x</var>, <var>y</var>)</em></dt>
<dd><span id="index-Kendall_0027s-Tau"></span>
<p>Compute Kendall’s
<var>tau</var>.
</p>
<p>For two data vectors <var>x</var>, <var>y</var> of common length <em>N</em>, Kendall’s
<var>tau</var>
is the correlation of the signs of all rank differences of
<var>x</var> and <var>y</var>; i.e., if both <var>x</var> and <var>y</var> have distinct
entries, then
</p>
<div class="example">
<pre class="example"> 1
<var>tau</var> = ------- SUM sign (<var>q</var>(i) - <var>q</var>(j)) * sign (<var>r</var>(i) - <var>r</var>(j))
N (N-1) i,j
</pre></div>
<p>in which the
<var>q</var>(i) and <var>r</var>(i)
are the ranks of <var>x</var> and <var>y</var>, respectively.
</p>
<p>If <var>x</var> and <var>y</var> are drawn from independent distributions,
Kendall’s
<var>tau</var>
is asymptotically normal with mean 0 and variance
<code>(2 * (2N+5)) / (9 * N * (N-1))</code>.
</p>
<p><code>kendall (<var>x</var>)</code> is equivalent to <code>kendall (<var>x</var>,
<var>x</var>)</code>.
</p>
<p><strong>See also:</strong> <a href="Basic-Statistical-Functions.html#XREFranks">ranks</a>, <a href="#XREFspearman">spearman</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Distributions.html" accesskey="n" rel="next">Distributions</a>, Previous: <a href="Basic-Statistical-Functions.html" accesskey="p" rel="prev">Basic Statistical Functions</a>, Up: <a href="Statistics.html" accesskey="u" rel="up">Statistics</a> [<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>
|