File: Correlation-and-Regression-Analysis.html

package info (click to toggle)
octave 3.6.2-5%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 71,636 kB
  • sloc: cpp: 241,186; fortran: 23,651; sh: 14,790; ansic: 7,153; lex: 3,761; objc: 3,404; yacc: 3,386; makefile: 2,073; awk: 985; perl: 838
file content (208 lines) | stat: -rw-r--r-- 10,427 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
<html lang="en">
<head>
<title>Correlation and Regression Analysis - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Statistics.html#Statistics" title="Statistics">
<link rel="prev" href="Statistical-Plots.html#Statistical-Plots" title="Statistical Plots">
<link rel="next" href="Distributions.html#Distributions" title="Distributions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Correlation-and-Regression-Analysis"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Distributions.html#Distributions">Distributions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Statistical-Plots.html#Statistical-Plots">Statistical Plots</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Statistics.html#Statistics">Statistics</a>
<hr>
</div>

<h3 class="section">26.4 Correlation and Regression Analysis</h3>

<!-- FIXME: Need Intro Here -->
<!-- cov scripts/statistics/base/cov.m -->
<p><a name="doc_002dcov"></a>

<div class="defun">
&mdash; Function File:  <b>cov</b> (<var>x</var>)<var><a name="index-cov-2470"></a></var><br>
&mdash; Function File:  <b>cov</b> (<var>x, opt</var>)<var><a name="index-cov-2471"></a></var><br>
&mdash; Function File:  <b>cov</b> (<var>x, y</var>)<var><a name="index-cov-2472"></a></var><br>
&mdash; Function File:  <b>cov</b> (<var>x, y, opt</var>)<var><a name="index-cov-2473"></a></var><br>
<blockquote><p>Compute the covariance matrix.

        <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>,&nbsp;<var>j</var>)-th<!-- /@w --> entry of
<code>cov (</code><var>x</var><code>, </code><var>y</var><code>)</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>.

     <pre class="example">          cov (x) = 1/N-1 * SUM_i (x(i) - mean(x)) * (y(i) - mean(y))
</pre>
        <p>If called with one argument, compute <code>cov (</code><var>x</var><code>, </code><var>x</var><code>)</code>, the
covariance between the columns of <var>x</var>.

        <p>The argument <var>opt</var> determines the type of normalization to use. 
Valid values are

          <dl>
<dt>0:<dd>  normalize with N-1, provides the best unbiased estimator of the
covariance [default]

          <br><dt>1:<dd>  normalize with N, this provides the second moment around the mean
</dl>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcorr.html#doc_002dcorr">corr</a>. 
</p></blockquote></div>

<!-- corr scripts/statistics/base/corr.m -->
   <p><a name="doc_002dcorr"></a>

<div class="defun">
&mdash; Function File:  <b>corr</b> (<var>x</var>)<var><a name="index-corr-2474"></a></var><br>
&mdash; Function File:  <b>corr</b> (<var>x, y</var>)<var><a name="index-corr-2475"></a></var><br>
<blockquote><p>Compute matrix of correlation coefficients.

        <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>,&nbsp;<var>j</var>)-th<!-- /@w --> entry of
<code>corr (</code><var>x</var><code>, </code><var>y</var><code>)</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>.

     <pre class="example">          corr (x,y) = cov (x,y) / (std (x) * std (y))
</pre>
        <p>If called with one argument, compute <code>corr (</code><var>x</var><code>, </code><var>x</var><code>)</code>,
the correlation between the columns of <var>x</var>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcov.html#doc_002dcov">cov</a>. 
</p></blockquote></div>

<!-- spearman scripts/statistics/base/spearman.m -->
   <p><a name="doc_002dspearman"></a>

<div class="defun">
&mdash; Function File:  <b>spearman</b> (<var>x</var>)<var><a name="index-spearman-2476"></a></var><br>
&mdash; Function File:  <b>spearman</b> (<var>x, y</var>)<var><a name="index-spearman-2477"></a></var><br>
<blockquote><p><a name="index-Spearman_0027s-Rho-2478"></a>Compute Spearman's rank correlation coefficient <var>rho</var>.

        <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>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>, and is
asymptotically normally distributed.

        <p><code>spearman (</code><var>x</var><code>)</code> is equivalent to <code>spearman (</code><var>x</var><code>,
</code><var>x</var><code>)</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dranks.html#doc_002dranks">ranks</a>, <a href="doc_002dkendall.html#doc_002dkendall">kendall</a>. 
</p></blockquote></div>

<!-- kendall scripts/statistics/base/kendall.m -->
   <p><a name="doc_002dkendall"></a>

<div class="defun">
&mdash; Function File:  <b>kendall</b> (<var>x</var>)<var><a name="index-kendall-2479"></a></var><br>
&mdash; Function File:  <b>kendall</b> (<var>x, y</var>)<var><a name="index-kendall-2480"></a></var><br>
<blockquote><p><a name="index-Kendall_0027s-Tau-2481"></a>Compute Kendall's <var>tau</var>.

        <p>For two data vectors <var>x</var>, <var>y</var> of common length <var>n</var>,
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

     <pre class="example">                   1
          tau = -------   SUM sign (q(i) - q(j)) * sign (r(i) - r(j))
                n (n-1)   i,j
</pre>
        <p class="noindent">in which the
<var>q</var>(<var>i</var>) and <var>r</var>(<var>i</var>)
are the ranks of <var>x</var> and <var>y</var>, respectively.

        <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 * (2</code><var>n</var><code>+5)) / (9 * </code><var>n</var><code> * (</code><var>n</var><code>-1))</code>.

        <p><code>kendall (</code><var>x</var><code>)</code> is equivalent to <code>kendall (</code><var>x</var><code>,
</code><var>x</var><code>)</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dranks.html#doc_002dranks">ranks</a>, <a href="doc_002dspearman.html#doc_002dspearman">spearman</a>. 
</p></blockquote></div>

<!-- FIXME: Need discussion of ols & gls and references to them in optim.txi -->
<!-- logistic_regression scripts/statistics/models/logistic_regression.m -->
   <p><a name="doc_002dlogistic_005fregression"></a>

<div class="defun">
&mdash; Function File: [<var>theta</var>, <var>beta</var>, <var>dev</var>, <var>dl</var>, <var>d2l</var>, <var>p</var>] = <b>logistic_regression</b> (<var>y, x, print, theta, beta</var>)<var><a name="index-logistic_005fregression-2482"></a></var><br>
<blockquote><p>Perform ordinal logistic regression.

        <p>Suppose <var>y</var> takes values in <var>k</var> ordered categories, and let
<code>gamma_i (</code><var>x</var><code>)</code> be the cumulative probability that <var>y</var>
falls in one of the first <var>i</var> categories given the covariate
<var>x</var>.  Then

     <pre class="example">          [theta, beta] = logistic_regression (y, x)
</pre>
        <p class="noindent">fits the model

     <pre class="example">          logit (gamma_i (x)) = theta_i - beta' * x,   i = 1 ... k-1
</pre>
        <p>The number of ordinal categories, <var>k</var>, is taken to be the number
of distinct values of <code>round (</code><var>y</var><code>)</code>.  If <var>k</var> equals 2,
<var>y</var> is binary and the model is ordinary logistic regression.  The
matrix <var>x</var> is assumed to have full column rank.

        <p>Given <var>y</var> only, <code>theta = logistic_regression (y)</code>
fits the model with baseline logit odds only.

        <p>The full form is

     <pre class="example">          [theta, beta, dev, dl, d2l, gamma]
             = logistic_regression (y, x, print, theta, beta)
</pre>
        <p class="noindent">in which all output arguments and all input arguments except <var>y</var>
are optional.

        <p>Setting <var>print</var> to 1 requests summary information about the fitted
model to be displayed.  Setting <var>print</var> to 2 requests information
about convergence at each iteration.  Other values request no
information to be displayed.  The input arguments <var>theta</var> and
<var>beta</var> give initial estimates for <var>theta</var> and <var>beta</var>.

        <p>The returned value <var>dev</var> holds minus twice the log-likelihood.

        <p>The returned values <var>dl</var> and <var>d2l</var> are the vector of first
and the matrix of second derivatives of the log-likelihood with
respect to <var>theta</var> and <var>beta</var>.

        <p><var>p</var> holds estimates for the conditional distribution of <var>y</var>
given <var>x</var>. 
</p></blockquote></div>

   </body></html>