3191
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
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{d}, @var{D}]} = diffpara (@var{x}, @var{a}, @var{b}) |
|
19 ## Return the estimator @var{d} for the differencing parameter of an |
3191
|
20 ## integrated time series. |
|
21 ## |
3449
|
22 ## The frequencies from @code{[2*pi*@var{a}/@var{T}, |
|
23 ## 2*pi*@var{b}/@var{T}]} are used for the estimation. If @var{b} is |
|
24 ## omitted, the interval @code{[2*pi/@var{T}, 2*pi*@var{a}/@var{T}]} is |
|
25 ## used. If both @var{b} and @var{a} are omitted then @code{@var{a} = |
|
26 ## 0.5 * sqrt(@var{T})} and @code{@var{b} = 1.5 * sqrt(@var{T})} is |
|
27 ## used, where @var{T} is the sample size. If @var{x} is a matrix, the |
|
28 ## differencing parameter of each column is estimated. |
3191
|
29 ## |
3449
|
30 ## The estimators for all frequencies in the intervals |
|
31 ## described above is returned in @var{D}. The value of @var{d} is |
|
32 ## simply the mean of @var{D}. |
3191
|
33 ## |
|
34 ## Reference: Brockwell, Peter J. & Davis, Richard A. Time Series: |
3449
|
35 ## Theory and Methods Springer 1987. |
|
36 ## @end deftypefn |
3426
|
37 |
3457
|
38 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
39 ## Description: Estimate the fractional differencing parameter |
3191
|
40 |
|
41 function [d, D] = diffpara (X, a, b) |
3426
|
42 |
3191
|
43 if ((nargin < 1) || (nargin > 3)) |
3449
|
44 usage ("[d, D] = diffpara (X, a, b)"); |
3191
|
45 else |
3457
|
46 if (is_vector (X)) |
3191
|
47 n = length (X); |
|
48 k = 1; |
|
49 X = reshape (X, n, 1); |
|
50 else |
3238
|
51 [n, k] = size(X); |
3191
|
52 endif |
|
53 if (nargin == 1) |
|
54 a = 0.5 * sqrt (n); |
|
55 b = 1.5 * sqrt (n); |
|
56 elseif (nargin == 2) |
|
57 b = a; |
|
58 a = 1; |
|
59 endif |
|
60 endif |
3426
|
61 |
3457
|
62 if (! (is_scalar (a) && is_scalar (b))) |
|
63 error ("diffpara: a and b must be scalars"); |
3191
|
64 endif |
3426
|
65 |
3191
|
66 D = zeros (b - a + 1, k); |
3426
|
67 |
3191
|
68 for l = 1:k |
3426
|
69 |
3191
|
70 w = 2 * pi * (1 : n-1) / n; |
3426
|
71 |
3457
|
72 x = 2 * log (abs (1 - exp (-i*w))); |
3191
|
73 y = log (periodogram (X(2:n,l))); |
3426
|
74 |
3191
|
75 x = center (x); |
|
76 y = center (y); |
3426
|
77 |
3191
|
78 for m = a:b |
|
79 D(m-a+1) = - x(1:m) * y(1:m) / sumsq (x(1:m)); |
|
80 endfor |
3426
|
81 |
3191
|
82 endfor |
3426
|
83 |
3191
|
84 d = mean (D); |
3426
|
85 |
3191
|
86 endfunction |
|
87 |