3191
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3191
|
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. |
3426
|
7 ## |
3191
|
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 |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3191
|
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 |
3449
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {} {[@var{pval}, @var{lm}] =} arch_test (@var{y}, @var{x}, @var{p}) |
|
19 ## For a linear regression model |
3191
|
20 ## |
3449
|
21 ## @example |
|
22 ## y = x * b + e |
|
23 ## @end example |
|
24 ## |
|
25 ## @noindent |
|
26 ## perform a Lagrange Multiplier (LM) test of the null hypothesis of no |
|
27 ## conditional heteroscedascity against the alternative of CH(@var{p}). |
|
28 ## |
3191
|
29 ## I.e., the model is |
3449
|
30 ## |
|
31 ## @example |
3499
|
32 ## y(t) = b(1) * x(t,1) + @dots{} + b(k) * x(t,k) + e(t), |
3449
|
33 ## @end example |
|
34 ## |
|
35 ## @noindent |
3499
|
36 ## given @var{y} up to @math{t-1} and @var{x} up to @math{t}, |
|
37 ## @math{e}(t) is @math{N(0, h(t))} with |
3449
|
38 ## |
|
39 ## @example |
3499
|
40 ## h(t) = v + a(1) * e(t-1)^2 + @dots{} + a(p) * e(t-p)^2, |
3449
|
41 ## @end example |
|
42 ## |
|
43 ## @noindent |
3499
|
44 ## and the null is @math{a(1)} == @dots{} == @math{a(p)} == 0. |
3191
|
45 ## |
3499
|
46 ## If the second argument is a scalar integer, @math{k}, perform the same |
|
47 ## test in a linear autoregression model of order @math{k}, i.e., with |
3449
|
48 ## |
|
49 ## @example |
3499
|
50 ## [1, y(t-1), @dots{}, y(t-@var{k})] |
3449
|
51 ## @end example |
3191
|
52 ## |
3449
|
53 ## @noindent |
3499
|
54 ## as the @math{t}-th row of @var{x}. |
3191
|
55 ## |
3449
|
56 ## Under the null, LM approximately has a chisquare distribution with |
3499
|
57 ## @var{p} degrees of freedom and @var{pval} is the @math{p}-value (1 |
3449
|
58 ## minus the CDF of this distribution at LM) of the test. |
|
59 ## |
3499
|
60 ## If no output argument is given, the @math{p}-value is displayed. |
3449
|
61 ## @end deftypefn |
3426
|
62 |
3457
|
63 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
64 ## Description: Test for conditional heteroscedascity |
3426
|
65 |
3191
|
66 function [pval, lm] = arch_test (y, X, p) |
|
67 |
|
68 if (nargin != 3) |
|
69 error ("arch_test needs 3 input arguments"); |
|
70 endif |
|
71 |
3457
|
72 if (! (is_vector (y))) |
|
73 error ("arch_test: y must be a vector"); |
3191
|
74 endif |
|
75 T = length (y); |
|
76 y = reshape (y, T, 1); |
|
77 [rx, cx] = size (X); |
|
78 if ((rx == 1) && (cx == 1)) |
|
79 X = autoreg_matrix (y, X); |
3457
|
80 elseif (! (rx == T)) |
|
81 error ("arch_test: either rows(X) == length(y), or X is a scalar"); |
3191
|
82 endif |
3457
|
83 if (! (is_scalar(p) && (rem(p, 1) == 0) && (p > 0))) |
3458
|
84 error ("arch_test: p must be a positive integer"); |
3191
|
85 endif |
3426
|
86 |
3191
|
87 [b, v_b, e] = ols (y, X); |
|
88 Z = autoreg_matrix (e.^2, p); |
|
89 f = e.^2 / v_b - ones (T, 1); |
|
90 f = Z' * f; |
|
91 lm = f' * inv (Z'*Z) * f / 2; |
|
92 pval = 1 - chisquare_cdf (lm, p); |
3426
|
93 |
3191
|
94 endfunction |