内部矩阵维度必须一致(对于GMM)

时间:2017-05-25 17:36:37

标签: matlab matrix

我知道这个问题很常见,我试图找出问题的来源,但我无法看到它。我试图估计一个GMM函数,我得到了这个错误"内部矩阵维度必须一致。"。我在第48行得到了错误(q = g * R')。 如果有人可以帮助我,我会非常感激。谢谢你提前。

    function [q] = Q(param,M,intr,cond)

   T = length(intr);

  % Population moments
  % [PMvec] = populat0ion_moments(param);
   %sigma = param(2);  
   alpha = param(1);
   beta = param(2);
   sigma = param(3);
   b = param(4);


   intert = intr(1:end-2,1);
   intertw = intr(2:end-1,1);

    a = zeros(1, T-2);
    c = zeros(1, T-2);
    d = zeros(1, T-2);
    e = zeros(1, T-2);

   for i=1:T-2

         a(:,i)=(intertw(i) - intert(i) - alpha - beta.*intertw(i));
         c(:,i) =(intertw(i) - intert(i) - alpha - beta.*intertw(i)).*intert(i);         
         d(:,i) =(intertw(i) - intert(i) - alpha - beta.*intertw(i)).^2 + (sigma^2).*(intert(i)).^(2*b);
         e(:,i) =((intertw(i) - intert(i) - alpha - beta.*intertw(i)).^2 + (sigma^2).*(intert(i)).^(2*b))*intert(i);
   end

   g(1,1)=1/(T-2.*1).*sum(a);

   g(1,2)=1/(T-2.*1).*sum(c);

   g(1,3)=1/(T-2.*1).*sum(d);

   g(1,4)=1/(T-2.*1).*sum(e);

  g;  

  % Sample moments and orthogonality conditions 

  % GMM matrix 
  % we are using diff algorithm for optimizing. we start using the seecond
  % one.
  %I.- Using 'lsqnonlin' function %the cholesky function multiplies the
%   %first part of the gmm estimator and we get very similar things
   R=chol(inv(M));
    q=g*R';
%      
%   II.- Using 'fminsearch' function
%q=g(cond)*inv(M)*g(cond)'; %GMM estimate (simplex method)

%SE_mu = sqrt(1/T * R(1,1));

0 个答案:

没有答案