Maximum Likelihood estimation - fminsearch

10 ビュー (過去 30 日間)
Kyriacos
Kyriacos 2013 年 3 月 7 日
Hi everyone,
I am trying to estimate a Vector Autoregression (VAR) model with two endogenous variables and one lag using maximum likelihood (ML). My idea is to use "fminsearch" in order to minimise the (-1)*(log-likelihood), equivalently maximise the log-likelihood. However, I make a mistake and I do not see where. In particular the code seems to get stuck at the initial conditions, no matter which they are. The log-likelihood function is:
LLF = -(T*n/2)*log(2*pi) + (T/2)*log(determinant(inverse(omega))) -0.5*sum(over t) [ (y(t) - A*x(t))'*inverse(omega)*(y(t) - A*x(t))]
where n is the number of endogenous variables, my case 2 T is the sample size y(t) is a 2*1 vector of endogenous variables x(t) are the regressors. since I assume one lag, these are lagged values of y omega is the variance-covariance matrix.
My code is below, I actually create the y and x series myself. It can be run by giving the initial conditions and then executing the function as follows:
x0 = [0.5 ; 0.36 ; 0.8 ; 0.2]; [x, fval, exitflag, output] = fminsearch(@likelihood_ist, x0) ;
Does anyone have any ideas? Thanks a lot!!
******** THE CODE
function F = likelihood_ist(x)
err1 = randn(100,1); err2 = randn(100,1);
v1=zeros(90,1); v2=zeros(90,1);
for i=2:91 v1(i)= 0.8*v1(i-1) + 0.56*v2(i-1) + err1(i); v2(i)= 0.6*v2(i-1) + 0.24*v1(i-1) + err2(i); end
v1(1) = [] ; v2(1) = [] ;
SampleSize = length(v1); nvars = 2 ;
c1 = x(1) ; c2 = x(2) ; c3 = x(3) ; c4 = x(4) ; A = [c1 c2 ; c3 c4] ; omega = cov(err1, err2);
y = [v1 v2] ; for i = 2:length(y) y1 = zeros(nvars, 1); xx= zeros(nvars,1) ; y1(1) = y(i,1) ; y1(2) = y(i,2) ; xx(1) = y(i-1, 1) ; xx(2) = y(i-1, 2) ; summing(i-1) = (y1-A*xx)'*(inv(omega))*(y1-A*xx); end
allsum = sum(summing) ; F = (-1)* ((-SampleSize*nvars/2)*log(2*pi)+(SampleSize/2)*log(det(inv(omega))) - 0.5*allsum) ;

回答 (1 件)

Matt J
Matt J 2013 年 3 月 7 日
編集済み: Matt J 2013 年 3 月 7 日
FIMINSEARCH experiments with different x, trying to find one that will reduce your -1*loglikelihood. Because your function output is also based on random quantities, however, changing x alone may not be enough to find a downward direction. If not, FMINSEARCH would give up.
Bottom line - your loglikelihood is not supposed to be stochastic.

カテゴリ

Help Center および File ExchangeDirect Search についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by