Mercurial > hg > octave-nkf
annotate scripts/signal/arch_test.m @ 10635:d1978e7364ad
Print name of function in error() string messages.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 22:26:54 -0700 |
parents | a1dbe9d80eee |
children | e00de2d5263c |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2005, 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 |
3191 | 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 ## | |
3191 | 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/>. | |
3191 | 19 |
3449 | 20 ## -*- texinfo -*- |
3909 | 21 ## @deftypefn {Function File} {[@var{pval}, @var{lm}] =} arch_test (@var{y}, @var{x}, @var{p}) |
3449 | 22 ## For a linear regression model |
3191 | 23 ## |
3449 | 24 ## @example |
25 ## y = x * b + e | |
26 ## @end example | |
27 ## | |
28 ## @noindent | |
29 ## perform a Lagrange Multiplier (LM) test of the null hypothesis of no | |
30 ## conditional heteroscedascity against the alternative of CH(@var{p}). | |
31 ## | |
3191 | 32 ## I.e., the model is |
3449 | 33 ## |
34 ## @example | |
3499 | 35 ## y(t) = b(1) * x(t,1) + @dots{} + b(k) * x(t,k) + e(t), |
3449 | 36 ## @end example |
37 ## | |
38 ## @noindent | |
3499 | 39 ## given @var{y} up to @math{t-1} and @var{x} up to @math{t}, |
40 ## @math{e}(t) is @math{N(0, h(t))} with | |
3449 | 41 ## |
42 ## @example | |
3499 | 43 ## h(t) = v + a(1) * e(t-1)^2 + @dots{} + a(p) * e(t-p)^2, |
3449 | 44 ## @end example |
45 ## | |
46 ## @noindent | |
3499 | 47 ## and the null is @math{a(1)} == @dots{} == @math{a(p)} == 0. |
3191 | 48 ## |
3499 | 49 ## If the second argument is a scalar integer, @math{k}, perform the same |
50 ## test in a linear autoregression model of order @math{k}, i.e., with | |
3449 | 51 ## |
52 ## @example | |
3499 | 53 ## [1, y(t-1), @dots{}, y(t-@var{k})] |
3449 | 54 ## @end example |
3191 | 55 ## |
3449 | 56 ## @noindent |
3499 | 57 ## as the @math{t}-th row of @var{x}. |
3191 | 58 ## |
3449 | 59 ## Under the null, LM approximately has a chisquare distribution with |
3499 | 60 ## @var{p} degrees of freedom and @var{pval} is the @math{p}-value (1 |
3449 | 61 ## minus the CDF of this distribution at LM) of the test. |
62 ## | |
3499 | 63 ## If no output argument is given, the @math{p}-value is displayed. |
3449 | 64 ## @end deftypefn |
3426 | 65 |
5428 | 66 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3457 | 67 ## Description: Test for conditional heteroscedascity |
3426 | 68 |
3191 | 69 function [pval, lm] = arch_test (y, X, p) |
70 | |
71 if (nargin != 3) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
72 error ("arch_test: 3 input arguments required"); |
3191 | 73 endif |
74 | |
4030 | 75 if (! (isvector (y))) |
3457 | 76 error ("arch_test: y must be a vector"); |
3191 | 77 endif |
78 T = length (y); | |
79 y = reshape (y, T, 1); | |
80 [rx, cx] = size (X); | |
81 if ((rx == 1) && (cx == 1)) | |
82 X = autoreg_matrix (y, X); | |
3457 | 83 elseif (! (rx == T)) |
84 error ("arch_test: either rows(X) == length(y), or X is a scalar"); | |
3191 | 85 endif |
4030 | 86 if (! (isscalar(p) && (rem(p, 1) == 0) && (p > 0))) |
3458 | 87 error ("arch_test: p must be a positive integer"); |
3191 | 88 endif |
3426 | 89 |
3191 | 90 [b, v_b, e] = ols (y, X); |
91 Z = autoreg_matrix (e.^2, p); | |
92 f = e.^2 / v_b - ones (T, 1); | |
93 f = Z' * f; | |
94 lm = f' * inv (Z'*Z) * f / 2; | |
95 pval = 1 - chisquare_cdf (lm, p); | |
3426 | 96 |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
97 endfunction |