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