1 ## Copyright (C) 1995-2012 Kurt Hornik
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
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})
21 ## Perform an F test for the null hypothesis rr * b = r in a classical
22 ## normal regression model y = X * b + e.
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.
27 ## The p-value (1 minus the CDF of this distribution at @var{f}) is
28 ## returned in @var{pval}.
30 ## If not given explicitly, @var{r} = 0.
32 ## If no output argument is given, the p-value is displayed.
35 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
36 ## Description: Test linear hypotheses in linear regression model
38 function [pval, f, df_num, df_den] = f_test_regression (y, x, rr, r)
40 if (nargin < 3 || nargin > 4)
45 if (! (isvector (y) && (length (y) == T)))
46 error ("f_test_regression: Y must be a vector of length rows (X)");
48 y = reshape (y, T, 1);
50 [q, c_R ] = size (rr);
52 error ("f_test_regression: RR must have as many columns as X");
57 if ((min (s_r) != 1) || (max (s_r) != q))
58 error ("f_test_regression: R must be a vector of length rows (RR)");
60 r = reshape (r, q, 1);
70 f = diff' * inv (rr * inv (x' * x) * rr') * diff / (q * v);
71 pval = 1 - fcdf (f, df_num, df_den);
74 printf (" pval: %g\n", pval);