annotate scripts/statistics/corrcoef.m @ 29359:7854d5752dd2

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 10:10:40 -0500
parents 90fea9cc9caa 0a5b15007766
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 ## Copyright (C) 2016-2021 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
7 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
8 ## This file is part of Octave.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23396
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23396
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
13 ## (at your option) any later version.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
14 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
18 ## GNU General Public License for more details.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
19 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23396
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
25
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
26 ## -*- texinfo -*-
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
27 ## @deftypefn {} {@var{r} =} corrcoef (@var{x})
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
28 ## @deftypefnx {} {@var{r} =} corrcoef (@var{x}, @var{y})
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
29 ## @deftypefnx {} {@var{r} =} corrcoef (@dots{}, @var{param}, @var{value}, @dots{})
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
30 ## @deftypefnx {} {[@var{r}, @var{p}] =} corrcoef (@dots{})
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
31 ## @deftypefnx {} {[@var{r}, @var{p}, @var{lci}, @var{hci}] =} corrcoef (@dots{})
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
32 ## Compute a matrix of correlation coefficients.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
33 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
34 ## @var{x} is an array where each column contains a variable and each row is
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
35 ## an observation.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
36 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
37 ## If a second input @var{y} (of the same size as @var{x}) is given then
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
38 ## calculate the correlation coefficients between @var{x} and @var{y}.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
39 ##
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
40 ## @var{param}, @var{value} are optional pairs of parameters and values which
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
41 ## modify the calculation. Valid options are:
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
42 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
43 ## @table @asis
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
44 ## @item @qcode{"alpha"}
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
45 ## Confidence level used for the bounds of the confidence interval, @var{lci}
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
46 ## and @var{hci}. Default is 0.05, i.e., 95% confidence interval.
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
47 ##
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
48 ## @item @qcode{"rows"}
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
49 ## Determine processing of NaN values. Acceptable values are @qcode{"all"},
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
50 ## @qcode{"complete"}, and @qcode{"pairwise"}. Default is @qcode{"all"}.
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
51 ## With @qcode{"complete"}, only the rows without NaN values are considered.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
52 ## With @qcode{"pairwise"}, the selection of NaN-free rows is made for each
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
53 ## pair of variables.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
54 ## @end table
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
55 ##
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
56 ## Output @var{r} is a matrix of Pearson's product moment correlation
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
57 ## coefficients for each pair of variables.
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
58 ##
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
59 ## Output @var{p} is a matrix of pair-wise p-values testing for the null
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
60 ## hypothesis of a correlation coefficient of zero.
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
61 ##
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
62 ## Outputs @var{lci} and @var{hci} are matrices containing, respectively, the
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
63 ## lower and higher bounds of the 95% confidence interval of each correlation
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
64 ## coefficient.
24547
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
65 ## @seealso{corr, cov}
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
66 ## @end deftypefn
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
67
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
68 ## FIXME: It would be good to add a definition of the calculation method
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
69 ## for a Pearson product moment correlation to the documentation.
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
70
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
71 function [r, p, lci, hci] = corrcoef (x, varargin)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
72
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
73 if (nargin == 0)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
74 print_usage ();
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
75 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
76
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
77 alpha = 0.05;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
78 rows = "all";
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
79
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
80 if (nargin > 1)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
81
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
82 ## Check for matrix argument y
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
83 if (isnumeric (varargin{1}))
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
84 y = varargin{1};
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
85 nx = numel (x);
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
86 ny = numel (y);
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
87 if (nx > 0 && ny > 0 && nx != ny)
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
88 error ("corrcoef: X and Y must be the same size");
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
89 endif
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
90 x = [x(:), y(:)];
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
91 varargin(1) = [];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
92 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
93
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
94 ## Check for Parameter/Value arguments
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
95 for i = 1:2:numel (varargin)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
96
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
97 if (! ischar (varargin{i}))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
98 error ("corrcoef: parameter %d must be a string", i);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
99 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
100 parameter = varargin{i};
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
101 if (i+1 > numel (varargin))
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
102 error ('corrcoef: parameter "%s" missing value', parameter);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
103 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
104 value = varargin{i+1};
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
105
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
106 switch (tolower (parameter))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
107 case "alpha"
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
108 if (isnumeric (value) && isscalar (value)
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
109 && value >= 0 && value <= 1)
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
110 alpha = value;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
111 else
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
112 error ('corrcoef: "alpha" must be a scalar between 0 and 1');
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
113 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
114
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
115 case "rows"
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
116 if (! ischar (value))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
117 error ('corrcoef: "rows" value must be a string');
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
118 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
119 value = tolower (value);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
120 switch (value)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
121 case {"all", "complete", "pairwise"}
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
122 rows = value;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
123 otherwise
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
124 error ('corrcoef: "rows" must be "all", "complete", or "pairwise"');
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
125 endswitch
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
126
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
127 otherwise
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
128 error ('corrcoef: Unknown option "%s"', parameter);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
129
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
130 endswitch
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
131 endfor
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
132 endif
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
133
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
134 if (strcmp (rows, "complete"))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
135 x(any (isnan (x), 2), :) = [];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
136 endif
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
137
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
138 if (isempty (x) || isscalar (x))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
139 r = p = lci = hci = NaN;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
140 return;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
141 endif
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
142
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
143 ## Flags for calculation
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
144 pairwise = strcmp (rows, "pairwise");
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23273
diff changeset
145 calc_pval = nargout > 1;
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
146
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
147 if (isrow (x))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
148 x = x(:);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
149 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
150 [m, n] = size (x);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
151 r = eye (n);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
152 if (calc_pval)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
153 p = eye (n);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
154 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
155 if (strcmp (rows, "pairwise"))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
156 mpw = m * ones (n);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
157 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
158 for i = 1:n
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
159 if (! pairwise && any (isnan (x(:,i))))
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
160 r(i,i) = NaN;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
161 if (nargout > 1)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
162 p(i,i) = NaN;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
163 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
164 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
165 for j = i+1:n
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
166 xi = x(:,i);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
167 xj = x(:,j);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
168 if (pairwise)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
169 idx = any (isnan ([xi xj]), 2);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
170 xi(idx) = xj(idx) = [];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
171 mpw(i,j) = mpw(j,i) = m - nnz (idx);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
172 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
173 r(i,j) = r(j,i) = corr (xi, xj);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
174 if (calc_pval)
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24547
diff changeset
175 df = m - 2;
24547
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
176 stat = sqrt (df) * r(i,j) / sqrt (1 - r(i,j)^2);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
177 cdf = tcdf (stat, df);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
178 p(i,j) = p(j,i) = 2 * min (cdf, 1 - cdf);
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
179 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
180 endfor
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
181 endfor
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
182
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
183 if (nargout > 2)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
184 if (pairwise)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
185 m = mpw;
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
186 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
187 CI = sqrt (2) * erfinv (1-alpha) ./ sqrt (m-3);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
188 lci = tanh (atanh (r) - CI);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
189 hci = tanh (atanh (r) + CI);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
190 endif
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
191
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
192 endfunction
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
193
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
194
24547
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
195 ## Compute cumulative distribution function for T distribution.
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
196 function cdf = tcdf (x, n)
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
197
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
198 if (iscomplex (x))
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
199 error ("tcdf: X must not be complex");
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
200 endif
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
201
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
202 if (isa (x, "single"))
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
203 cdf = zeros (size (x), "single");
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
204 else
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
205 cdf = zeros (size (x));
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
206 endif
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
207
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
208 k = ! isinf (x) & (n > 0);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
209
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
210 xx = x .^ 2;
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
211 x_big_abs = (xx > n);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
212
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
213 ## deal with the case "abs(x) big"
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
214 kk = k & x_big_abs;
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
215 cdf(kk) = betainc (n ./ (n + xx(kk)), n/2, 1/2) / 2;
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
216
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
217 ## deal with the case "abs(x) small"
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
218 kk = k & ! x_big_abs;
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
219 cdf(kk) = 0.5 * (1 - betainc (xx(kk) ./ (n + xx(kk)), 1/2, n/2));
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
220
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
221 k &= (x > 0);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
222 if (any (k(:)))
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
223 cdf(k) = 1 - cdf(k);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
224 endif
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
225
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
226 k = isnan (x) | !(n > 0);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
227 cdf(k) = NaN;
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
228
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
229 k = (x == Inf) & (n > 0);
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
230 cdf(k) = 1;
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
231
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
232 endfunction
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
233
fdc9ce839afd maint: Remove statistics functions which have been shifted to Octave Forge package.
Rik <rik@octave.org>
parents: 24534
diff changeset
234
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
235 %!test
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
236 %! x = rand (5);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
237 %! r = corrcoef (x);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
238 %! assert (size (r) == [5, 5]);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
239
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
240 %!test
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
241 %! x = [1, 2, 3];
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
242 %! r = corrcoef (x);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
243 %! assert (size (r) == [1, 1]);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
244
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
245 %!assert (isnan (corrcoef ([])))
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
246 %!assert (isnan (corrcoef (NaN)))
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
247 %!assert (isnan (corrcoef (1)))
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
248
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
249 %!test
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
250 %! x = [NaN, NaN];
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
251 %! r = corrcoef (x);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
252 %! assert (size(r) == [1, 1] && isnan (r));
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
253
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
254 %!test
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
255 %! x = rand (5);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
256 %! [r, p] = corrcoef (x);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
257 %! assert (size (r) == [5, 5] && size (p) == [5 5]);
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
258 %! assert (diag (r), ones (5,1), eps);
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
259
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
260 %!test
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
261 %! x = rand (5,1);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
262 %! y = rand (5,1);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
263 %! R1 = corrcoef (x, y);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
264 %! R2 = corrcoef ([x, y]);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
265 %! assert (R1, R2);
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
266 %! R3 = corrcoef (x.', y.');
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
267 %! assert (R1, R3);
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
268
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
269 %!test
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
270 %! x = [1;2;3];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
271 %! y = [1;2;3];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
272 %! r = corrcoef (x, y);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
273 %! assert (r, ones (2,2));
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
274
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
275 %!test
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
276 %! x = [1;2;3];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
277 %! y = [3;2;1];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
278 %! r = corrcoef (x, y);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
279 %! assert (r, [1, -1; -1, 1]);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
280
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
281 %!test
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
282 %! x = [1;2;3];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
283 %! y = [1;1;1];
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
284 %! r = corrcoef (x, y);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
285 %! assert (r, [1, NaN; NaN, 1]);
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
286
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27923
diff changeset
287 %!error <Invalid call> corrcoef ()
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
288 %!error <parameter 1 must be a string> corrcoef (1, 2, 3)
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
289 %!error <parameter "alpha" missing value> corrcoef (1, 2, "alpha")
26238
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
290 %!error <"alpha" must be a scalar> corrcoef (1,2, "alpha", "1")
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
291 %!error <"alpha" must be a scalar> corrcoef (1,2, "alpha", ones (2,2))
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
292 %!error <"alpha" must be a scalar between 0 and 1> corrcoef (1,2, "alpha", -1)
71d618146e4c corrcoef.m: Clean up function.
Rik <rik@octave.org>
parents: 25054
diff changeset
293 %!error <"alpha" must be a scalar between 0 and 1> corrcoef (1,2, "alpha", 2)
23273
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
294 %!error <"rows" must be "all"...> corrcoef (1,2, "rows", "foobar")
87b6f3606fd4 corrcoef.m: New statistics function for Matlab compatibility (bug #47824).
Guillaume Flandin
parents:
diff changeset
295 %!error <Unknown option "foobar"> corrcoef (1,2, "foobar", 1)