Mercurial > hg > octave-nkf
annotate scripts/signal/arch_test.m @ 15107:03381a36f70d
generate convenience libraries for new parse-tree and interpfcn subdirectories
* src/Makefile.am (liboctinterp_la_SOURCES): Include octave.cc in the
list, not $(DIST_SRC).
(liboctinterp_la_LIBADD): Include octave-value/liboctave-value.la,
parse-tree/libparse-tree.la, interp-core/libinterp-core.la,
interpfcn/libinterpfcn.la, and corefcn/libcorefcn.la in the list.
* src/interp-core/module.mk (noinst_LTLIBRARIES): Add
interp-core/libinterp-core.la to the list.
(interp_core_libinterp_core_la_SOURCES): New variable.
* src/interpfcn/module.mk (noinst_LTLIBRARIES): Add
interpfcn/libinterpfcn.la to the list.
(interpfcn_libinterpfcn_la_SOURCES): New variable.
* src/parse-tree/module.mk (noinst_LTLIBRARIES): Add
parse-tree/libparse-tree.la to the list.
(parse_tree_libparse_tree_la_SOURCES): New variable.
* src/octave-value/module.mk (noinst_LTLIBRARIES): Add
octave-value/liboctave-value.la to the list.
(octave_value_liboctave_value_la_SOURCES): New variable.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 05 Aug 2012 09:04:30 -0400 |
parents | 5d3a684236b0 |
children | 1c89599167a6 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1995-2012 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3191 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3191 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3191 | 18 |
3449 | 19 ## -*- texinfo -*- |
3909 | 20 ## @deftypefn {Function File} {[@var{pval}, @var{lm}] =} arch_test (@var{y}, @var{x}, @var{p}) |
3449 | 21 ## For a linear regression model |
3191 | 22 ## |
3449 | 23 ## @example |
24 ## y = x * b + e | |
25 ## @end example | |
26 ## | |
27 ## @noindent | |
28 ## perform a Lagrange Multiplier (LM) test of the null hypothesis of no | |
29 ## conditional heteroscedascity against the alternative of CH(@var{p}). | |
30 ## | |
3191 | 31 ## I.e., the model is |
3449 | 32 ## |
33 ## @example | |
3499 | 34 ## y(t) = b(1) * x(t,1) + @dots{} + b(k) * x(t,k) + e(t), |
3449 | 35 ## @end example |
36 ## | |
37 ## @noindent | |
3499 | 38 ## given @var{y} up to @math{t-1} and @var{x} up to @math{t}, |
39 ## @math{e}(t) is @math{N(0, h(t))} with | |
3449 | 40 ## |
41 ## @example | |
3499 | 42 ## h(t) = v + a(1) * e(t-1)^2 + @dots{} + a(p) * e(t-p)^2, |
3449 | 43 ## @end example |
44 ## | |
45 ## @noindent | |
3499 | 46 ## and the null is @math{a(1)} == @dots{} == @math{a(p)} == 0. |
3191 | 47 ## |
3499 | 48 ## If the second argument is a scalar integer, @math{k}, perform the same |
49 ## test in a linear autoregression model of order @math{k}, i.e., with | |
3449 | 50 ## |
51 ## @example | |
3499 | 52 ## [1, y(t-1), @dots{}, y(t-@var{k})] |
3449 | 53 ## @end example |
3191 | 54 ## |
3449 | 55 ## @noindent |
3499 | 56 ## as the @math{t}-th row of @var{x}. |
3191 | 57 ## |
3449 | 58 ## Under the null, LM approximately has a chisquare distribution with |
3499 | 59 ## @var{p} degrees of freedom and @var{pval} is the @math{p}-value (1 |
3449 | 60 ## minus the CDF of this distribution at LM) of the test. |
61 ## | |
3499 | 62 ## If no output argument is given, the @math{p}-value is displayed. |
3449 | 63 ## @end deftypefn |
3426 | 64 |
5428 | 65 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3457 | 66 ## Description: Test for conditional heteroscedascity |
3426 | 67 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10680
diff
changeset
|
68 function [pval, lm] = arch_test (y, x, p) |
3191 | 69 |
70 if (nargin != 3) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
71 error ("arch_test: 3 input arguments required"); |
3191 | 72 endif |
73 | |
4030 | 74 if (! (isvector (y))) |
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
|
75 error ("arch_test: Y must be a vector"); |
3191 | 76 endif |
77 T = length (y); | |
78 y = reshape (y, T, 1); | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10680
diff
changeset
|
79 [rx, cx] = size (x); |
3191 | 80 if ((rx == 1) && (cx == 1)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10680
diff
changeset
|
81 x = autoreg_matrix (y, x); |
3457 | 82 elseif (! (rx == T)) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 error ("arch_test: either rows (X) == length (Y), or X is a scalar"); |
3191 | 84 endif |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 if (! (isscalar (p) && (rem (p, 1) == 0) && (p > 0))) |
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
|
86 error ("arch_test: P must be a positive integer"); |
3191 | 87 endif |
3426 | 88 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10680
diff
changeset
|
89 [b, v_b, e] = ols (y, x); |
3191 | 90 Z = autoreg_matrix (e.^2, p); |
91 f = e.^2 / v_b - ones (T, 1); | |
92 f = Z' * f; | |
93 lm = f' * inv (Z'*Z) * f / 2; | |
10680
e00de2d5263c
Replace calls to obsolete chisquare_cdf with chi2cdf.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
94 pval = 1 - chi2cdf (lm, p); |
3426 | 95 |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
96 endfunction |