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