| 1 |
function of = fn_a0cfreefun_tv(b,nvar,nStates,n0cumsum,Ui,Tkave,Del00invcell_ave,dpDelp0cell_ave) |
| 2 |
% of = fn_a0cfreefun_tv(b,nvar,nStates,n0cumsum,Ui,Tkave,Del00invcell_ave,dpDelp0cell_ave) |
| 3 |
% Negative logPosterior function for squeesed free A0 parameters (bar tv structural variances) in |
| 4 |
% a new SZ time-varying model, which are vectorized as b's in the WZ notation. In other words, |
| 5 |
% A0 parameters can be fully time varying, but the time varying structural variances will be |
| 6 |
% excluded. It differs from fn_a0sfreefun*.m in several aspects: |
| 7 |
% (a) can deal with equations with only structural variances time varying; |
| 8 |
% (b) take care of lag restrictions; |
| 9 |
% (c) conditional on the values of all other parameters including A+. |
| 10 |
% Note: (1) columns correspond to equations; (2) c stands for constant or for an exclusion of |
| 11 |
% time varying structural variances. |
| 12 |
% See TBVAR NOTE p. 61. |
| 13 |
% |
| 14 |
% b: n0cumsum(end)-by-1 vector of free constant A0 parameters, vectorized from b_ihatcell. |
| 15 |
% nvar: Number of endogeous variables. |
| 16 |
% nStates: Number of states. |
| 17 |
% n0cumsum: [0;cumsum(n0)] where n0 is nvar-by-1 and its ith element represents the number of |
| 18 |
% free constant A0 parameters in ith equation for *all states*. |
| 19 |
% Ui: nvar-by-1 cell. In each cell, nvar*nStates-by-(qi+si) orthonormal basis for the null of the ith |
| 20 |
% equation contemporaneous restriction matrix where qi is the number of free parameters |
| 21 |
% within the state and si is the number of free parameters across the states. |
| 22 |
% With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector |
| 23 |
% of total original parameters and bi is a vector of free parameters. When no |
| 24 |
% restrictions are imposed, we have Ui = I. There must be at least one free |
| 25 |
% parameter left for the ith equation. |
| 26 |
% Tkave: nStates-by-1 of sample sizes (excluding lags but including dummies if provided) for different states k, |
| 27 |
% averaged (ave) over E-step draws. For T_k. See p.61. In the Gibbs-Metropolis step, there is |
| 28 |
% no need to make Tk the same as Tkave (See Chib and Jeliazkov 2001). |
| 29 |
% Del00invcell_ave: Quardratic term for b0_j in each cell. See p.61. When fn_a0cfreegrad_tv.m is used, |
| 30 |
% always make this systemetric by using (Del00invcell_ave'+Del00invcell_ave)/2. |
| 31 |
% Also note that in the Gibbs-Metropolis step, there is no need to make Del00invcell the same |
| 32 |
% as Del00invcell_ave (See Chib and Jeliazkov 2001). |
| 33 |
% dpDelp0cell_ave: Cross d+_j and b0_j term in each cell. See p.61. In the Gibbs-Metropolis step, there is no need |
| 34 |
% to make dpDelp0cell the same as dpDelp0cell_ave (See Chib and Jeliazkov 2001). |
| 35 |
%---------------- |
| 36 |
% of: Objective function (negative logPosterior). |
| 37 |
% |
| 38 |
% This function is called by szeml*.m which is a bettern program than tveml*.m. Thus, |
| 39 |
% use this function in place of fn_a0sfreefun2.m if possible. |
| 40 |
% See fn_a0cfreegrad_tv.m for analytical gradient for this function. |
| 41 |
% |
| 42 |
% Tao Zha, September 2001 |
| 43 |
% |
| 44 |
% Copyright (C) 1997-2012 Tao Zha |
| 45 |
% |
| 46 |
% This free software: you can redistribute it and/or modify |
| 47 |
% it under the terms of the GNU General Public License as published by |
| 48 |
% the Free Software Foundation, either version 3 of the License, or |
| 49 |
% (at your option) any later version. |
| 50 |
% |
| 51 |
% It is distributed in the hope that it will be useful, |
| 52 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 53 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 54 |
% GNU General Public License for more details. |
| 55 |
% |
| 56 |
% If you did not received a copy of the GNU General Public License |
| 57 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 58 |
% |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
A0_shat=zeros(nvar,nvar,nStates); % Arranged A0 matrix across states. |
| 63 |
|
| 64 |
tra = 0.0; |
| 65 |
for kj = 1:nvar |
| 66 |
bj = b(n0cumsum(kj)+1:n0cumsum(kj+1)); |
| 67 |
A0_shat(:,kj,:) = reshape(Ui{kj}*bj,nvar,nStates); |
| 68 |
tra = tra+0.5*( (bj'*Del00invcell_ave{kj})*bj - 2*dpDelp0cell_ave{kj}*bj ); % Negative exponential term |
| 69 |
end |
| 70 |
|
| 71 |
ada=0.0; |
| 72 |
for si=1:nStates % See p.34a. |
| 73 |
[A0l,A0u] = lu(A0_shat(:,:,si)); |
| 74 |
ada = ada - Tkave(si)*sum(log(abs(diag(A0u)))); % Negative log determinant of A0 raised to power T |
| 75 |
end |
| 76 |
|
| 77 |
of = ada + tra; |