# [R] transcript a matlab code in R

From: Fotis Papailias <fpapailias_at_gmail.com>
Date: Fri, 25 Jul 2008 19:24:03 +0100

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 :

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

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

```

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_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help