robustvcv matlab function error message

Good morning to everyone, I had an error when I try to estimate a robust variance covariance matrix, using robustvcv. In particular, I want to evaluate the variance covariance matrix of a matrix of data (a matrix with 4683 x 20 observations), using the prameters estimated from fmincon.
I use the following syntax:
[vcv]=robustvcv('f', pars, 0, data), where data is the original matrix of input data of the f function, 'f' is a functiont that returns, as first output a scalar(sum of loglikelihood) and a second input a vector Tx1 of loglikelihood values, as required by function robustvcv. 0 is the usual value that refers to the lag.
pars is a 1x82 vector of parameters estimated from fmin* ,but I get the following error message:
Index in position 1 exceeds array bounds (must not exceed 1).
Could someone tell me what could cause the error message?
I use the same function robustvcv on a vector 1x4 parameters, but using a vector Tx1 of observations, and it gives me the right answer, without error.

7 个评论

Has everyone suggestions?
Alessandra - where did you get the robustvcv function? Is it included in a MATLAB toolbox or is this third party code or something that you have written?
It's a function of Mfe toolbox of Sheppard
Alessandra - please copy and paste the full error message to this question so that we can get an idea of which line is throwing the error. You may also want to include your f function (just attach it).
Now, it seems it goes to infinite loop. The function is in the file attached below.
I think there could be some errors in the code; even if the feval function gives me the exact result of likelihood, when I debugged the hessian_2sided function, which is called by robustvc, I noted that gm and gp take the same values, and the same happens for Hm and Hp. All these variables have the final value of loglikehood, thus in H I get only NAN.
n = size(x,1);
if size(x,2)~=1
error('X must be a column vector.')
end
try
feval(f,x,varargin{:});
catch FE
errtxt=['There was an error evaluating the function. Please check the arguements. The specific error was:' FE.message];
error(errtxt);
end
fx = feval(f,x,varargin{:});
% Compute the stepsize (h)
h = eps.^(1/3)*max(abs(x),1e-8);
xh = x+h;
h = xh-x;
ee = sparse(1:n,1:n,h,n,n);
% Compute forward and backward steps
gp = zeros(n,1);
gm = zeros(n,1);
for i=1:n
gp(i) = feval(f,x+ee(:,i),varargin{:});
gm(i) = feval(f,x-ee(:,i),varargin{:});
end
hh=h*h';
Hm=NaN*ones(n);
Hp=NaN*ones(n);
% Compute "double" forward and backward steps
for i=1:n
for j=i:n
Hp(i,j) = feval(f,x+ee(:,i)+ee(:,j),varargin{:});
Hp(j,i)=Hp(i,j);
Hm(i,j) = feval(f,x-ee(:,i)-ee(:,j),varargin{:});
Hm(j,i)=Hm(i,j);
end
end
%Compute the hessian
H = zeros(n);
for i=1:n
for j=i:n
H(i,j) = (Hp(i,j)-gp(i)-gp(j)+fx+fx-gm(i)-gm(j)+Hm(i,j))/hh(i,j)/2;
H(j,i) = H(i,j);
end
end

请先登录,再进行评论。

回答(0 个)

产品

版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by