Dear R-users,

I am trying to translate a matlab code for calculating the Local Whittle
estimator in time series with long memory originally written by Shimotsu and
available free in his webpage (
http://www.econ.queensu.ca/pub/faculty/shimotsu/ )

The Matlab code is

=======================================================================================

function[r] = whittle(d,x,m)
% WHITTLE.M computes the local Whittle likelihood, which uses
% the periodogram of data x accoding to the definition
%
%        Ixx(k) = w(x)*conj(w(x)),
%
%    where
%                                  N
%        w(k) =  (2*pi*n)^(-1/2)  sum  x(t)*exp(i*2*pi*(k-1)*t/N), 1 <= k <=
N.
%                                   t=1
%
%                                           Katsumi Shimotsu, April 1999
%
%         INPUT    x: data (n*1 vector)
%                m: truncation number
%                d: parameter value
%____________________________________________________________________________

[n,nn] = size(x);
t = (0:1:n-1)';
lambda = 2*pi*t/n;
wx = (2*pi*n)^(-1/2)*conj(fft(conj(x))).*exp(i*lambda);
lambda = lambda(2:m+1);
wx = wx(2:m+1);
Ix = wx.*conj(wx);

g = mean((lambda.^(2*d)).*Ix);
r = log(g) - 2*d*mean(log(lambda));

=================================================================================

and when you want to use it, you just call the function, and you minimize
it. (In other words you minimize the "r" expression on the last line above.)



I have done a lot efforts to translate it and I have ended up with the
following :


=======================================================================================

local.whittle <- function(d, x, m)
{
n <- length(x)
t <- matrix(c(0:n1), nrow = n, ncol=1)
lambda <- (2*pi*t)/n
wx <- (2*pi*n)^(-1/2)*Conj(fft( Conj(x)))*exp(1i*lambda)
M1 <- m+1
lambda2 <- lambda[2:M1]
wx2 <- wx[2:M1]
ix <- wx2*Conj(wx2)
g <- mean((lambda2^(2*d))*ix)
r <- log(mean((lambda2^(2*d))*ix)) - 2*d*mean(log(lambda2))
}

=======================================================================================

which seems to run, but when I am trying to call the function and minimize
it using:


e <- optimize(local.whittle, x, m, c(-0.5, 0.5))
e1 <- e$minimum


I get the following error and I cannot find the reason why.


=======================================================================================

Error in optimize(lw, x, m, c(-0.5, 0.5)) :
  invalid function value in 'optimize'
In addition: Warning messages:
1: In 2:M1 : numerical expression has 2 elements: only the first used
2: In 2:M1 : numerical expression has 2 elements: only the first used

=======================================================================================


Please help me.

thanks. fotis.


P.S.: as far as for a long memory estimator in time series introduced by
Robinson (1995) that I was asking some days ago, I have written a code. Send
me an e-mail if you need it, till I include it  in some package.

-- 
fp

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to