home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / signal / arch_tes.m < prev    next >
Text File  |  1999-04-29  |  3KB  |  70 lines

  1. ## Copyright (C) 1995, 1996, 1997  Kurt Hornik
  2. ## 
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this file.  If not, write to the Free Software Foundation,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  [pval, lm] = arch_tes (y, X, p)
  18. ##         [pval, lm] = arch_tes (y, k, p)
  19. ##
  20. ## arch_tes (y, X, p) performs a Lagrange Multiplier (LM) test of the
  21. ## null hypothesis of no conditional heteroscedascity in the linear
  22. ## regression model y = X * b + e against the alternative of CH(p).   
  23. ## I.e., the model is
  24. ##     y(t) = b(1) * x(t,1) + ... + b(k) * x(t,k) + e(t),
  25. ## where given y up to t-1 and x up to t, e(t) is N(0, h(t)) with
  26. ##     h(t) = v + a(1) * e(t-1)^2 + ... + a(p) * e(t-p)^2,
  27. ## and the null is a(1) == ... == a(p) == 0.
  28. ##
  29. ## arch_tes (y, k, p) does the same in a linear autoregression model of
  30. ## order k, i.e., with [1, y(t-1), ..., y(t-k)] as the t-th row of X. 
  31. ##
  32. ## Under the null, lm approximately has a chisquare distribution with p
  33. ## degrees of freedom.  pval is the p-value (1 minus the CDF of this
  34. ## distribution at lm) of the test.
  35. ##
  36. ## If no output argument is given, the p-value is displayed.
  37.   
  38. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  39. ## Description:  Test for conditional heteroscedascity
  40.   
  41. function [pval, lm] = arch_tes (y, X, p)
  42.  
  43.   if (nargin != 3)
  44.     error ("arch_tes needs 3 input arguments");
  45.   endif
  46.  
  47.   if !(is_vec (y))
  48.     error ("arch_tes:  y must be a vector");
  49.   endif
  50.   T   = length (y);
  51.   y   = reshape (y, T, 1);
  52.   [rx, cx] = size (X);
  53.   if ((rx == 1) && (cx == 1))
  54.     X = auto_mat (y, X);
  55.   elseif !(rx == T)
  56.     error (["arch_tes:  ", ...
  57.         "either rows(X) == length(y), or X is a scalar"]);
  58.   endif
  59.   if !(is_scal(p) && (rem(p, 1) == 0) && (p > 0))
  60.     error ("arch_tes:  p must be a positive integer.");
  61.   endif
  62.   
  63.   [b, v_b, e] = ols (y, X);
  64.   Z    = auto_mat (e.^2, p);
  65.   f    = e.^2 / v_b - ones (T, 1);
  66.   f    = Z' * f;
  67.   lm   = f' * inv (Z'*Z) * f / 2;
  68.   pval = 1 - chi2_cdf (lm, p);
  69.   
  70. endfunction