Mercurial > hg > octave-nkf
annotate scripts/statistics/tests/f_test_regression.m @ 20327:094ae7cc2d1d
pt_PT.ts: update portuguese translation.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 23 Apr 2015 12:48:37 +0100 |
parents | 9fc020886ae9 |
children | d9341b422488 |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1995-2015 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3200 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3200 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3200 | 18 |
3454 | 19 ## -*- texinfo -*- |
3499 | 20 ## @deftypefn {Function File} {[@var{pval}, @var{f}, @var{df_num}, @var{df_den}] =} f_test_regression (@var{y}, @var{x}, @var{rr}, @var{r}) |
16826
a4969508008e
doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
21 ## Perform an F test for the null hypothesis @nospell{rr * b = r} in a |
a4969508008e
doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
22 ## classical normal regression model y = X * b + e. |
3200 | 23 ## |
3454 | 24 ## Under the null, the test statistic @var{f} follows an F distribution |
25 ## with @var{df_num} and @var{df_den} degrees of freedom. | |
3200 | 26 ## |
3454 | 27 ## The p-value (1 minus the CDF of this distribution at @var{f}) is |
28 ## returned in @var{pval}. | |
29 ## | |
30 ## If not given explicitly, @var{r} = 0. | |
3200 | 31 ## |
32 ## If no output argument is given, the p-value is displayed. | |
3454 | 33 ## @end deftypefn |
3200 | 34 |
5428 | 35 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 36 ## Description: Test linear hypotheses in linear regression model |
3200 | 37 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
38 function [pval, f, df_num, df_den] = f_test_regression (y, x, rr, r) |
3426 | 39 |
3200 | 40 if (nargin < 3 || nargin > 4) |
6046 | 41 print_usage (); |
3200 | 42 endif |
43 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
44 [T, k] = size (x); |
4030 | 45 if (! (isvector (y) && (length (y) == T))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
46 error ("f_test_regression: Y must be a vector of length rows (X)"); |
3200 | 47 endif |
48 y = reshape (y, T, 1); | |
3426 | 49 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
50 [q, c_R ] = size (rr); |
3200 | 51 if (c_R != k) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
52 error ("f_test_regression: RR must have as many columns as X"); |
3200 | 53 endif |
3426 | 54 |
3200 | 55 if (nargin == 4) |
56 s_r = size (r); | |
57 if ((min (s_r) != 1) || (max (s_r) != q)) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
58 error ("f_test_regression: R must be a vector of length rows (RR)"); |
3200 | 59 endif |
60 r = reshape (r, q, 1); | |
61 else | |
62 r = zeros (q, 1); | |
63 endif | |
64 | |
65 df_num = q; | |
66 df_den = T - k; | |
3426 | 67 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
68 [b, v] = ols (y, x); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
69 diff = rr * b - r; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
70 f = diff' * inv (rr * inv (x' * x) * rr') * diff / (q * v); |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
71 pval = 1 - fcdf (f, df_num, df_den); |
3426 | 72 |
3200 | 73 if (nargout == 0) |
3456 | 74 printf (" pval: %g\n", pval); |
3200 | 75 endif |
76 | |
77 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
78 |