# Problem estimating variance-covariance matrix of multivariate normal with restrictions on variance-covariance using Maximum Likelihood.

2 views (last 30 days)
O.Hubert on 9 Nov 2016
Commented: charles alexander on 21 Nov 2020
Hi all,
I am estimating a Vector Autoregression Model using Maximum Likelihood where I impose constraints on the variance-covariance matrix of residuals.
For Maximum Likelihood estimation, the set of parameters to optimize on is the set of betas coefficients and the sigmas, the variance-covariance matrix of residuals.
For this I am using fmincon where I pass the constraints and initial values. I am able to correctly impose restrictions on the regression coefficients but my procedure cannot "update" the varianc-covariance parameters. They remain stuck at their initial value. What I mean by that is that my procedure correctly estimates the betas coefficients but completely disregards the variance-covariance matrix.
I have tried the following:
• Pass as initial values only the betas coefficients. This gives me the same answer as when I include the initial values for the variance-covariance matrix.
To clear things up, I post here the code to test:
% Main script
y=rand(100,3); % creates the dependent matrix
x=[ones(99,1) y(1:end-1,:)]; % creates the independent matrix
y=y(2:end,:); % accommodates the size
Ny=size(y,2); % number of dependent variables
[T,Nx]=size(x); % number of independent variables
betas_init=[zeros(1,3) ; diag(repmat(0.4,3,1))]; % initial values for betas
sigmas_init=cov(y); % initial values for sigmas; does not matter which I put
initparam=[vec(betas_init) ; vec(sigmas_init)];
% Testing restrictions
Aeq=zeros(1,length(initparam));
Aeq(1,1+Ny*Nx)=1;
beq(1,1)=0.0004; % value can be changed
% Calling fmincon
[optparam] = fmincon(@(allparam) VAR_likelihood(y,x,allparam),[initparam],[],[],Aeq,beq,[],[],[],options);
% Function to be called
function [sum_lik]=VAR_likelihood(y,x,allparam)
[T,Nx]=size(x);
Ny=size(y,2);
betas=reshape(allparam(1:Nx*Ny),Nx,Ny); % gather the betas parameters from initparam/allparam
sigmas=reshape(allparam(1+Nx*Ny:Nx*Ny+Ny*Ny),Ny,Ny); % gather the sigmas parameters from initparam/allparam
cond_mean=[];
errors=[];
cond_mean=x*betas;
errors=y-cond_mean;
allparam(1+Nx*Ny:Nx*Ny+Ny*Ny)=vec(errors'*errors/(T-1)); % pass the variance-covariance matrix to the set of params.
sigmas=reshape(allparam(1+Nx*Ny:Nx*Ny+Ny*Ny),Ny,Ny);
pdf=1/(((2*pi())^(Ny/2))*sqrt(det(sigmas))).* ... % compute the density
exp(-0.5.*sum(errors/(sigmas).*(errors),2));
sum_lik = -sum(log(pdf)); % => same as Stata
fprintf(1,['The value of the likelihood is ' num2str(sum_lik),'\n']);
end
% Testing if the restrictions have been taken into account
pred=x*reshape(optparam(1:Nx*Ny),Nx,Ny);
error=y-pred;
varcov=error'*error/(T-1); % Clearly,
varcov == reshape(optparam(1+Nx*Ny:end),Ny,Ny) % but the restriction is passed to optparam.
I do not see why I am unable to pass the updating of the variance-covariance matrix to the allparam/optparam vector.
Thank you very much.
##### 1 CommentShow NoneHide None
charles alexander on 21 Nov 2020
there is an error in the size of x.
in the % main script,
the end -1 is wrong, it is +1. this creates the independent matrix for x.
try this, i hope it helps.